Show in graph
DB

Software → Databases

Foreign Key

A relational constraint where values in one table refer to primary keys in another table.

Motivation

A foreign key solves the problem of keeping relationships between tables valid.

Where it fits

It belongs to relational databases and data modeling.

Mental model

A foreign key says: this value must refer to an existing row somewhere else.

Important details

Foreign keys help enforce referential integrity and make domain relationships explicit in the database.

Common mistakes

  • Skipping foreign keys because the application “should handle it”.
  • Confusing joins with foreign key constraints.