Foreign key constraints are responsible for data referential integrity in your database. Simply put, referential integrity means that when a record in a table refers to a corresponding record in another table, that corresponding record must exist. So, a foreign key constraint specifies that the values in a column (or a group of columns) must match the values appearing in some row of another table. A reference sets a foreign key constraint on the referencing table. In order to create a foreign key in MySQL, you need the following:
See also: |