Cascade Mysql foreign keys, NO ACTION, Restrict, SET NULL

Meaning foreign key constraint pair table: 

   If no candidate key in the parent table, is not allowed for insert / update on the sub-table 

Meaning foreign key constraints on the parent table: 

   For update / delete to update or delete the subtable corresponding to one or more of the candidate when the key matching row, the behavior depends on the parent table is the parent table: the outer key specified in the definition of sub-tables on update / on delete clause, InnoDB supports five ways, are as follows 
  

  1. Cascade mode 

When the update / delete records in the parent table, the synchronization update / delete records in the child table out matching 
On delete cascade from available starting mysql3.23.50; on update cascade from available starting mysql4.0.8 

   2. set null mode 

When the update / delete records, the sub-matching records in the table on the parent table columns set to null 
to pay attention to the child table foreign key column can not be null is not 
the On the Delete the SET null is available starting mysql3.23.50; on update set null from mysql4 .0.8 start available 

  3. No action mode 

If a matching record in the child table is not allowed to the parent table corresponds to a candidate key update / delete operations 
This is the standard ANSI SQL-92, beginning from the support mysql4.0.8 

   4. Restrict manner 

With no action, foreign key constraints are checked immediately 

  5. Set default mode 

Parser know the action, but Innodb not recognize, do not know what that means. .
  
   Note: trigger will not be affected by foreign key cascade behavior, that the solution will not trigger hair
   If no candidate key in the parent table, is not allowed for insert / update on the sub-table 

Meaning foreign key constraints on the parent table: 

   For update / delete to update or delete the subtable corresponding to one or more of the candidate when the key matching row, the behavior depends on the parent table is the parent table: the outer key specified in the definition of sub-tables on update / on delete clause, InnoDB supports five ways, are as follows 
  

  1. Cascade mode 

When the update / delete records in the parent table, the synchronization update / delete records in the child table out matching 
On delete cascade from available starting mysql3.23.50; on update cascade from available starting mysql4.0.8 

   2. set null mode 

When the update / delete records, the sub-matching records in the table on the parent table columns set to null 
to pay attention to the child table foreign key column can not be null is not 
the On the Delete the SET null is available starting mysql3.23.50; on update set null from mysql4 .0.8 start available 

  3. No action mode 

If a matching record in the child table is not allowed to the parent table corresponds to a candidate key update / delete operations 
This is the standard ANSI SQL-92, beginning from the support mysql4.0.8 

   4. Restrict manner 

With no action, foreign key constraints are checked immediately 

  5. Set default mode 

Parser know the action, but Innodb not recognize, do not know what that means. .
  
   Note: trigger will not be affected by foreign key cascade behavior, that the solution will not trigger hair

Guess you like

Origin www.cnblogs.com/kinwing/p/11102244.html