MySQL Cascade operations

Source: Internet
Author: User

transferred from: http://blog.csdn.net/codeforme/article/details/5539454
foreign KEY constraints The meaning of the child table:
Insert/update is not allowed on a child table if a candidate key is not found in the parent table
What foreign KEY constraints mean to the parent table:
when you 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, as follows
. Cascade Mode
when a record is update/delete on the parent table, the synchronization update/delete the matching record of the child table, and the ON DELETE cascade is available from mysql3.23.50; On UPDATE cascade starting from mysql4.0.8 Available
. Set Null method
when you update/delete a record on a parent table, set the column of the matching record on the child table to NULL, noting that the foreign key column of the child table cannot be not NULL, and that the on delete set NULL is available from mysql3.23.50; on update set n Ull available starting from mysql4.0.8
  . No Action Mode
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, which is the ANSI SQL-92 standard, which is supported starting from mysql4.0.8
  . 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 ... Note: Trigger will not be affected by foreign key cascade behavior, that is, it will not be solved trigger
in MySQL, three points that are inconsistent with the SQL standard
1. If there are more than one key value in the parent table, then when the foreign key check is made, the other rows with the same key value do not exist, for example, when a restrict behavior foreign key is defined, a child table row corresponds to more than one parent table row (with the same key value). InnoDB does not allow all these rows on the parent table to be deleted
2. Parent-child table is the same table, when self-referencing is not allowed to specify on UPDATE cascade, ON update set NULL
allows on delete set null from the same table starting with mysql4.0.13
starting with mysql4.0.21, the ON DELETE Cascade is allowed on the same table
However, cascading levels cannot exceed
3, InnoDB when checking the unique,constraint constraint, it is row by row rather than statement or transaction end;
The constraint check in the SQL standard is when the statement execution is complete

MySQL Cascade operations

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.