← Back to topic library
Dev MaxxingIntermediateDatabases75 sec
Foreign key
A foreign key is a column in one table that references another table's primary key, linking a row to a related row elsewhere.
Prerequisite: Primary key
What matters
This linking is what lets a relational database represent connections, like each order belonging to a customer, while keeping the data for each in its own table.
Example
An 'orders' table might have a 'customer_id' foreign key, linking each order back to the specific customer row it belongs to.
Common misconception
A foreign key does not duplicate the referenced row's data; it simply stores a reference, letting the full related data be looked up when needed.
Recall question
What does a foreign key let a database represent between two tables?
Keywords and related concepts
foreign keyrelationshipsdatabaseprimary key