NEW
Also known as: FK
A constraint linking a table’s column values to another table’s primary key to enforce referential integrity.
DESCRIPTION
A foreign key enforces relationships between tables in a relational database by requiring values to match a referenced primary key. It prevents orphaned records and preserves data consistency across related entities. Foreign keys support cascading behaviors on updates and deletes, improving integrity management. They are foundational to normalized schemas and enable joins that combine related data efficiently. Proper indexing and selective cascading help maintain performance and predictability.
ALTERNATIVE DEFINITIONS
Microsoft Learn
A foreign key is a column or combination of columns used to enforce a link between the data in two tables.
Emphasizes enforcement of a link and relational integrity.
PostgreSQL Documentation
A foreign key constraint specifies that the values in a column (or a group of columns) must match the values appearing in some row of another table.
Highlights matching values across tables and constraint semantics.
MySQL Reference Manual
A FOREIGN KEY is a constraint that requires the values in the child table to match values in the parent table, to enforce referential integrity.
Stresses parent–child relationship and integrity enforcement.
RELATED TERMS
Referential Integrity Relational Database Join Feature Scaling Unique Constraint Composite Key Index Entity-Relationship Model
COMPETING TERMS
RELATIONS
- Broader: Key
KNOWLEDGE AREAS
Data Modeling Data Architecture Data Storage & Operations Data Management
TARGET AUDIENCE
Data Modeler Data Engineer Data Architect BI Specialist Data Analyst
EXTERNAL SOURCES
- Wikipedia - Foreign key
- Microsoft - SQL Server foreign key relationships guide
- PostgreSQL - Foreign key constraints in PostgreSQL
- Oracle - Integrity constraints overview
TOP QUESTIONS
Why is a Foreign Key important in relational databases?
A Foreign Key preserves referential integrity by preventing orphaned records and inconsistent relationships. This ensures trustworthy joins and reliable analytics across related tables.
Category: Relevancy
How does a Foreign Key differ from a Primary Key?
A Primary Key uniquely identifies a row within a table, while a Foreign Key references a Primary Key in another table to define a relationship. They are complementary constraints.
Category: Misunderstanding
What happens on delete with a Foreign Key constraint?
Depending on the rule, deletes can cascade, set values to NULL or default, or be restricted. Choosing the right action avoids unwanted data loss.
Category: Risks
Do Foreign Keys impact query performance?
Yes. They can add overhead on writes but improve data quality and join logic. Proper indexing mitigates performance costs on updates and deletes.
Category: Performance
When should you avoid using a Foreign Key?
In extremely high-throughput systems where referential checks are externalized, teams may omit Foreign Keys—at the cost of increased data quality risk.
Category: Opinion
Can a Foreign Key reference a composite Primary Key?
Yes. Composite Foreign Keys must match the referenced composite Primary Key columns in order and data type.
Category: Requirements
How do Foreign Keys support normalization?
They enforce structured relationships between entities, allowing decomposition into normalized tables without losing linkage integrity.
Category: Concept
Are Foreign Keys required for joins?
Joins can be executed without defined Foreign Keys, but explicit constraints help ensure correctness and maintainability.
Category: Misunderstanding
What are common mistakes with Foreign Keys?
Unindexed Foreign Key columns, overly broad cascade rules, and mismatched data types are frequent issues that hurt performance and integrity.
Category: Mistakes