![]() |
Foreign keys enable tables in a relational database to be linked together. |
![]() |
A foreign key is a set of attributes in table T1 that reference another set of corresponding primary key attributes in table T2. |
![]() |
The foreign key attributes in T1 must have the same domain as the corresponding primary key attributes in T2. |
![]() |
Each value that occurs in the foreign key must also occur in the primary key unless the foreign key value is NULL. |
![]() |
For example, |
![]() |
If a library database has two tables: student member and department shown in Figure 6.2. | |
![]() |
The student member table has primary key matriculation number and the department table has primary key department number. | |
![]() |
The two tables can be linked with each other using the department number attribute. | |
![]() |
Thus, department number in the student member table will be a foreign key linked to the department number attribute in the department table which is its primary key. | |
![]() |
Note that a foreign key is usually denoted by an asterisk (*). |
