When a foreign key constraint is enforced in a relational database, which…
2024
When a foreign key constraint is enforced in a relational database, which condition must normally be satisfied while inserting a non-NULL value into the foreign key column?
- A.
The value can be inserted without checking the referenced table.
- B.
The value must match an existing value in the referenced primary key or unique key column.
- C.
A new primary key value is automatically generated in the parent table.
- D.
The foreign key checks only uniqueness of the inserted value.
- E.
The foreign key column must always contain NULL values.
Attempted by 61 students.
Show answer & explanation
Correct answer: B
A foreign key (FK) enforces referential integrity between a child table and a parent (referenced) table. The rule is: every non-NULL value placed in the foreign key column must already exist as a value in the referenced primary key (or unique/candidate key) column of the parent table.
This prevents "orphan" rows that point to a parent record that does not exist. So when you insert a non-NULL FK value, the database first checks the referenced table; if no matching parent value is found, the INSERT is rejected with a foreign-key-violation error. (A NULL is allowed and bypasses this check, but the question specifically concerns a non-NULL value.)
Therefore the condition that must be satisfied is: the inserted value must match an existing value in the referenced primary/unique key column. The correct option is "The value must match an existing value in the referenced primary key or unique key column."