MySQL FOREIGN key
1. What is a foreign key
A specific relationship between a table and a table. Maintain the integrity and consistency of your data.
User table
Order Orders Form
1.1 Delete the user, do not delete the order, the data is inconsistent
Insert record in 1.2 order table
Foreign Key control: Let the user do not update the data, or the user delete the data when the order synchronization also deleted
2. Foreign Key Features:
2.1 To see if a foreign key exists:
2.1.1 InnoDB type
Show CREATE TABLE name:
engine--Storage Engine
The 2.1.2 foreign key is a constraint relationship between two tables.
2.1.3 The name of the foreign key is unique.
3. Create key FOREIGN key
CREATE TABLE table name (column definition index definition foreign key definition [constraint constraint name] foreign key[foreign key field]
references[foreign Key Name] (Foreign key field)
[on Delete{retrict|cascade|set null | no action}]
[on Update{restrict|cascade|set null|no Action}])
Restrict: Deny delete or update to parent table
Cascade: Delete or update of the parent table, automatically delete or update the corresponding record in the child table.
Set NULL parent table Delete, UPDATE, setting Word table foreign key field null
No action: Do not act.
To delete a foreign key:
MySQL Lesson three