Definition: Foreign keys are the columns of a table that points to the primary key of another table. They act as a cross-reference between tables.
For example:
In the below example the Stu_Id
column in Course_enrollment
table is a foreign key as it points to the primary key of the Student table.
Course_enrollment table:
Course_Id | Stu_Id |
C01 | 101 |
C02 | 102 |
C03 | 101 |
C05 | 102 |
C06 | 103 |
C07 | 102 |
Student table:
Stu_Id | Stu_Name | Stu_Age |
101 | Chaitanya | 22 |
102 | Arya | 26 |
103 | Bran | 25 |
104 | Jon | 21 |
Note: Practically, the foreign key has nothing to do with the primary key tag of another table, if it points to a unique column (not necessarily a primary key) of another table then too, it would be a foreign key. So, a correct definition of foreign key would be: Foreign keys are the columns of a table that points to the candidate key of another table.
Leave a Reply