This question already has an answer here:

Aside from indexing the value of the foreign key, what is/are the advantage of assigning foreign keys to databases? I've seen a lot of databases that does not assign foreign keys, but is relational by their schema. One example is the database of the wiki (mediawiki). I've studied their schema and although their tables are interconnected using the primary key of one table, they aren't assigning any foreign keys.

marked as duplicate by ypercubeᵀᴹ, Max Vernon, Mark Storey-Smith, RolandoMySQLDBA mysql Aug 12 '14 at 21:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


A foreign key is a type of constraint. The purpose of constraints is to make sure that data in tables follows certain rules.

You use foreign key constraints to ensure that child data has parent data. You can use it to either prevent orphaning child records or to facilitate cascade deletes or updates.


From FOREIGN KEY Constraints in the product documentation:

A foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data in two tables. You can create a foreign key by defining a FOREIGN KEY constraint when you create or modify a table.


A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table. A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, verification of all values that make up the FOREIGN KEY constraint is skipped. To make sure that all values of a composite FOREIGN KEY constraint are verified, specify NOT NULL on all the participating columns.

Not the answer you're looking for? Browse other questions tagged or ask your own question.