If I have a relationship between two tables (both tables have their own primary keys) what should guide my decision as to which table should store the foreign key? I understand
Like a primary key
, a foreign key
is also a type of constraint
placed on one or more columns in a table.
The foreign key
establishes a link between the key columns and related columns in another table. (You can also link the foreign key columns to columns within the same table.)
The table that contains the foreign key is considered the child table, and the table that the foreign key references is the parent table.
Key Points
foreign key
must reference a primary key or unique constraint, although that reference can be on the same table or on a different tableforeign key
must also have the same number of columns as the number of columns in the referenced constraint, and the data types must match between corresponding columns.Primary key
, Foreign key
columns can contain NULL values.