Skip to main content

What is a foreign key (FOREIGN KEY)?

A foreign key (FOREIGN KEY) is a field or combination of fields in one table that references the primary key of another table, creating a link between the tables.

The main points

  1. A link between tables: a foreign key shows that a record in one table is connected to a record in another table.
  2. Supporting data integrity: the database checks that the foreign key's value matches an existing value of the other table's primary key.
  3. Example:
  • The Employees table has a DepartmentID field (a foreign key) that references the ID field in the Departments table.
  • That means every employee is tied to an existing department.
  1. Updates and deletes: when a record in the parent table changes or is deleted, the behavior can be configured, blocking the delete, or cascading the delete or update.

Put simply, a foreign key is a "reference" to another table, linking records together and keeping data consistent across tables.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.