Foreign keys

The information in one table is related to that in other tables by foreign keys.

Example

The demo database has one table holding employee information and one table holding department information. The Departments table has these columns:

To find the name of a particular employee's department, there is no need to put the name of the employee's department into the Employees table. Instead, the Employees table contains a column holding the employee's department ID. This is called a foreign key to the Departments table. A foreign key references a particular row in the table containing the corresponding primary key or unique constraint. The primary key and unique constraint so referenced are known as the candidate key.

In this example, the Employee table (which contains the foreign key in the relationship) is called the foreign table or referencing table. The Department table (which contains the referenced primary key) is called the primary table or the referenced table.