References and Foreign Keys

Top Previous Next

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:

Both tables are to be InnoDB or Falcon tables
The following syntax should be used: FOREIGN_KEY (fk_fieldname) REFERENCES table_name (fieldname)
The field being declared a foreign key requires to be declared as an index in the table definition.

See also:
Diagram Objects: Creating a Reference | Creating a Many-to-Many Reference | Reference Editor | Reference Manager | Manual Reference Drawing