Databases

Foreign key

A constraint that links a column in one table to the primary key of another, enforcing referential integrity so that orphan rows cannot exist.

Foreign keys prevent the application from inserting a row that references a parent that does not exist, or deleting a parent while children still point to it. The cost is that every INSERT and DELETE must check the referenced table, which can become a bottleneck under high write load. CASCADE options automate the propagation (delete children when the parent is deleted) but must be used carefully - a cascade on a large table can hold locks for an unexpectedly long time.

Implemented by

Learn it in context

Related concepts