ITPEC FE Morning October 2022 Question 26

Topic: DatabasesAlso asked in October 2019

In a relational database, which of the following is an appropriate purpose for defining a foreign key?

Explanation

A constraint that keeps references between related tables consistent — a foreign key enforces referential integrity.

A foreign key is a column, or set of columns, whose values must match the primary key of another table or be NULL. With orders.customer_code referencing customers.customer_code, the DBMS rejects an order for a customer code that does not exist, and rejects (or cascades, if so defined) deleting a customer who still has orders. No row can point at something that is not there.

Answer (b)

Why not others:

  • •(a) — fragmentation from repeated deletes and inserts is a physical storage problem, fixed by reorganising the storage area
  • •(c) — restoring damaged records is recovery, done from backups and the log (roll forward), not from relationships between tables
  • •(d) — storing related rows physically close together is clustering, a performance measure rather than a constraint

Key rule: Keys and constraints protect the logical correctness of the data; storage layout, speed and failure recovery are handled by separate DBMS mechanisms.

Databases · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.