Specifying a Foreign Key with FOREIGN KEY
I described foreign keys in “Foreign Keys” in Chapter 2, but I’ll review the basics here:
A foreign key is a mechanism that associates two tables.
A foreign key is a column (or set of columns) in a table whose values relate to, or reference, values in some other table.
A foreign key ensures that rows in one table have corresponding rows in another table, called the referenced table or parent table.
A foreign key establishes a direct relationship to a primary key or candidate key in the referenced table, so foreign-key values are restricted to parent-key values that already exist. This restriction is called referential integrity.
A foreign key, unlike a primary key, can permit nulls.
A table can have zero ...
Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.