References and Foreign Keys
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.
You can define a foreign key in any MySQL table type, including the default MyISAM table type, but they do not anything - the are only used to enforce referential integrity in InnoDB tables.
In order to create a foreign key in MySQL, you need the following:
-
Both tables are to be InnoDB tables
-
The following syntax should be used: FORIGN_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.
Database Designer for MySQL will help you to do it in one action by creating a reference between two tables.
To learn more about references using, please refer to the Tutorial - Creating Your First Diagram.
Diagram Objects: Creating a Reference | Reference Editor
©2005 MicroOLAP Technologies LTD. All Rights Reserved. All trademarks are the sole property of their respective owners.