Back to Lingo

Foreign Key

A foreign key is a constraint in a relational database that links a column in one table to the primary key of another table. It enforces referential integrity, ensuring that relationships between tables remain valid. When defined, a foreign key prevents inserting rows with invalid references or deleting referenced rows unless constraints allow cascading.

Why it matters

Foreign keys maintain consistency across related tables and prevent broken or orphaned data. They are a foundation of normalized relational database design and essential for modeling real-world relationships.

Examples

A posts table may include a user_id that references the primary key of a users table. Lessons like Relationships Between Tables explain relational links.

See More

Further Reading

You need to be signed in to leave a comment and join the discussion