Mysqlinnodb foreign key Mysql foreign key
BitsCN.com
Mysql innodb foreign key
Meanings of foreign key constraints on subtables:
If no candidate key is found in the parent table, insert/update is not allowed in the child table.
Description of the foreign key constraint on the parent table:
When updating or deleting a parent table to update or delete one or more candidate keys that match the row in the child table, the behavior of the parent table depends on: the on update/on delete clause specified when defining the foreign key of the sub-table. InnoDB supports five methods, which are listed as follows:
. Cascade method
When updating/deleting records in the parent table, synchronize update/delete matching records in the child table
On delete cascade is available from mysql3.23.50; on update cascade is available from mysql4.0.8
. Set null
When updating/deleting records in the parent table, set the columns of matched records in the child table to null.
Note that the foreign key column of the sub-table cannot be not null.
On delete set null is available from mysql3.23.50; on update set null is available from mysql4.0.8
. No action method
If the child table has matched records, the update/delete operation on the candidate keys corresponding to the parent table is not allowed.
This is ANSI SQL-92 standard, supported since mysql4.0.8
. Restrict method
The same as no action, both check foreign key constraints immediately
. Set default mode
The parser recognizes this action, but Innodb cannot recognize it and doesn't know what it means...
Note: trigger is not affected by the cascade action of the foreign key, that is, trigger is not released.
BitsCN.com