Introduction
A foreign key is a field (or collection of fields) in one table
that uniquely identifies a row of another table. The table
containing the foreign key is called the child table, and the
table containing the candidate key is called the referenced or
parent table. The purpose of the foreign key is to identify a
particular row of the referenced table. Therefore, it is required
that the foreign key is equal to the candidate key in some row of
the primary table, or else have no value (the NULL
value). This is called a referential integrity constraint between
the two tables. Because violations of these constraints can be
the source of many database problems, most database management
systems provide mechanisms to ensure that every non-null foreign
key corresponds to a row of the referenced table. Consider
following simple example:
create table parent (
id int not null primary key,
name char(80)
) …[Read more]