Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Answer:
A foreign key is used to represent the relationship between 2 tables in a database. It is an attribute whose value is derived from the primary key of another table.
Example:
Department
Dept_id |
Dept_name |
1011 |
Sales |
1021 |
IT |
1031 |
HR |
Employee
Employee_id |
Employee_name |
Dept_id |
Emp_Email |
101 |
Ravi Kumar |
1011 |
|
102 |
Tarun A |
1012 |
|
103 |
Jennifer Davis |
1013 |
|
104 |
Martin Woods |
1013 |
|
105 |
Ron Romy |
1012 |
Dept_id is the primary key of table Department but in the table Employee, Dept_id is a foreign key.