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?

  1. A.

    The value can be inserted without checking the referenced table.

  2. B.

    The value must match an existing value in the referenced primary key or unique key column.

  3. C.

    A new primary key value is automatically generated in the parent table.

  4. D.

    The foreign key checks only uniqueness of the inserted value.

  5. 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."

Explore the full course: Niacl Ao It Specialist