Introduction:
What is foreign
key is the most common question asked in interview from freshers. I have tried
to explain foreign key in my article in detail i.e. definition, how to create
it and implementation.
What is a Foreign Key?
In simple words A FOREIGN KEY is field in one table which points to a PRIMARY KEY field in another table.
A foreign key is a column(s) in one
table that references the primary key of another table. The purpose of the
foreign key is to ensure referential integrity of the data.
The referenced table is
called the parent table while the table with the foreign key is
called the child table.
Implementation: Let’s
understand the concept of
foreign key constraint by implementing it
on tables. For this we are going to create two table Dept_Table and Emp_table.