An attribute or set of attributes in one table that refers to the primary key in another table of a Relational Database.

It is used to establish and enforce a link between the data in two tables.

Properties

  • Referential Integrity: the value in the foreign key column must match an existing value in the referenced primary key column, preventing orphaned records.
  • Relationship: it creates a parent-child relationship between tables, where the table containing the foreign key is the child and the table being referenced is the parent.
  • Constraints: foreign keys can be configured with specific actions, such as ON DELETE CASCADE or ON UPDATE SET NULL, to define how changes in the parent table affect the child table.
  • Nullability: unlike a primary key, a foreign key can contain NULL values unless a NOT NULL constraint is explicitly applied.