Cascade in MySQL, NO ACTION, Restrict, SET NULL

Source: Internet
Author: User

Reprinted from: http://blog.163.com/inflexible_simple/blog/static/1676946842011616102543931/

FOREIGN key constraint meaning for child table:  
   If a candidate key is not found in the parent table, INSERT/UPDATE&NBSP is not allowed on the child table;

The meaning of the foreign key constraint 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 is determined by the on update/on delete clause that is specified when the foreign key of the child table is defined, InnoDB supports 5 ways of  ,
  
  . Cascade mode  
when Update/delete record on parent table, synchronize update/ Delete   the matching record of the child table;
on DELETE cascade available from mysql3.23.50, on UPDATE cascade mysql4.0.8 from  

   . Set NULL mode  
when Update/delete records on the parent table, set the column of matching records on the child table to null 
Note that the foreign key column of the child table cannot be null 
on Delete set Null starting from mysql3.23.50 available; On update set NULL &NBSP available from mysql4.0.8;

  . No action mode  
If there is a matching record in the child table, the Update/delete action for the parent table corresponding to the candidate key is not allowed  
This is the ANSI SQL-92 standard, starting from mysql4.0.8 support  

  . Restrict mode  
No action, check foreign KEY constraint immediately  

  . Set default mode   The
Parser recognizes this action, but InnoDB does not recognize it and does not know what it means ...  
  
   Note: Trigger is not affected by foreign key cascade behavior, that is, trigger

Cascade in MySQL, NO ACTION, Restrict, SET NULL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.