1. Only the InnoDB engine allows the use of foreign keys, so our datasheets must use the InnoDB engine.
2. Note:
1, must use the InnoDB engine;
2, foreign keys must be indexed (index);
3, foreign key binding relationship use "on DELETE CASCADE" here, meaning that if the foreign key corresponding data is deleted, the associated data is completely deleted,
3. The update operation is similar, because we have already defined the foreign key Delete, the update operation is cascade when the table is built earlier, so we can test the data directly here.
4. Use foreign keys to make simultaneous deletions and updates to multiple associated tables, thus ensuring consistency of data.
. Cascade Way
Synchronize update/delete out a matching record of a child table when Update/delete records on the parent table
On DELETE cascade available from mysql3.23.50; On UPDATE cascade available starting from mysql4.0.8
. Set NULL mode
Set the column of the matching record on the child table to NULL when the record is update/delete on the parent table
Note that the foreign key column of the child table cannot be not NULL
On delete Set NULL is available from mysql3.23.50; On update set NULL is available starting from mysql4.0.8
. No Action Mode
If there are matching records in the child table, the Update/delete action is not allowed for the parent table corresponding to the candidate key
This is the ANSI SQL-92 standard, starting from mysql4.0.8 support
. Restrict Way
Same no action, check foreign KEY constraints immediately
. Set default mode
The parser recognizes this action, but InnoDB does not recognize it and does not know what it means ...
Foreign keys are only allowed with InnoDB