Foreign key

Foreign keys are used to identify data records which are stored in other database tables but are related to data records from the current table. Departments are saved in the following table.

Primary keyDepartment
1Sales
2Marketing
3Support

The next table contains employee data.

Primary keyDepartmentFirst nameLast name
13BettyMiller
22SamCook
32RalfMiller
41SamHampton

The primary key of the department is saved as the foreign key in the Department column. This makes it very simple to identify, for example, that Betty Miller works in the Support department.