FOREIGN KEY constraints The meaning of a child table: If a candidate key is not found in the parent table, the insert/update is not allowed on the child table
What foreign key constraints mean to the parent table: when update/delete on a parent table to update or delete a candidate key that has one or more matching rows in the child table, the behavior of the parent table depends on the on update/on delete clause that is specified when the foreign key of the child table is defined, INNODB supports 5 ways , broken down as follows
1. Cascade the matching record of the child table is synchronized update/delete when the record is update/delete on the parent table
On DELETE cascade available from mysql3.23.50; On UPDATE cascade available starting from mysql4.0.8
2. Set NULL when Update/delete records on a parent table, sets the column of matching records on the child table to null
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
3. No action if there is a matching record 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
4. Restrict mode with no action, are immediately check foreign KEY constraints
5. Set Default mode parser recognizes this action, but InnoDB does not recognize it and does not know what it means ...
Note: Trigger will not be affected by foreign key cascade behavior, that is, it will not be solved trigger
MySQL foreign key Cascade, NO ACTION, Restrict, SET NULL