What is the primary purpose of a foreign key in a relational database?

Options

  • A. To encrypt data
  • B. To maintain referential integrity between related tables
  • C. To sort records automatically
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. To maintain referential integrity between related tables

Detailed Explanation

  • Foreign key: Establishes a relationship between tables by referencing a candidate key, commonly a primary key.
  • Referential integrity: Ensures that references point to valid records, subject to the defined constraints.
  • It helps maintain consistency between related tables.