MySQL foreign key Cascade, NO ACTION, Restrict, SET NULL

Source: Internet
Author: User

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

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.