Google News
logo
MySQL - Interview Questions
What is a foreign key? Write a query to implement the same in MySQL.
A foreign key is used to connect two tables. A FOREIGN KEY is a field (or assortment of it) in one table that alludes to the PRIMARY KEY in another table. The FOREIGN KEY requirement is utilised to forestall activities that would crush joins between tables.
 
To assign a foreign key, it is important to mention it while creating the table. It can be assigned by invoking the FOREIGN KEY query. Something like this :
 
FOREIGN KEY (Any_ID) REFERENCES Table_to_reference(Any_ID)
Advertisement