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 key | Department |
1 | Sales |
2 | Marketing |
3 | Support |
The next table contains employee data.
Primary key | Department | First name | Last name |
1 | 3 | Betty | Miller |
2 | 2 | Sam | Cook |
3 | 2 | Ralf | Miller |
4 | 1 | Sam | Hampton |
The primary key of the department is saved here as a foreign key in the "Department" column. This makes it very simple to identify, for example, that Betty Miller works in the Support department.