Mysql on cascade

Source: Internet
Author: User

Description of the foreign key constraint of Mysql on cascade for the sub-table: if the candidate key cannot be found in the parent table, the meaning of the foreign key constraint of insert/update on the sub-table to the parent table is not allowed: when updating or deleting a parent table to update or delete one or more candidate keys that match the row in the child table, the behavior of the parent table depends on: the on update/on delete clause specified when defining the foreign key of the sub-Table. InnoDB supports five methods, which are listed as follows. when the cascade method is used to update/delete records in the parent table, The On delete cascade method is used to synchronize the update/delete matching records of the child table from mysql3.23.50. on update cascade is available from mysql4.0.8. when the set null method is used to update/delete records on the parent table, set the columns of matching records in 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 from mysql4.0.8. no action mode if the child table has matched records, the parent table corresponding to the candidate key cannot be updated/delete operation this is ANSI SQL-92 standard, from mysql4.0.8 support. the Restrict method is the same as the no action method. Both check the foreign key constraints immediately. the Set default method parser recognizes this action, but Innodb cannot recognize it and does not know what it means... note: trigger will not be affected by the cascade action of the foreign key, that is, trigger will not be released in mysql, which is in violation of the SQL standard. if multiple key values are the same in the parent table, when performing a foreign key check, other rows with the same key value will not exist; for example, when a restrict behavior foreign key is defined, a child table row corresponds to multiple parent table rows (with the same key value), Innodb cannot delete all these rows in the parent table. parent and Child tables are the same table. You are not allowed to specify on update cascade for reference. on update set null starts from mysql4.0.13 and allows on delete set null on the same table to start from mysql4.0.21, allow the on delete cascade of the same table, but the cascade level cannot exceed 15 or 3. When Innodb checks the unique and constraint constraints, the row by row instead of the statement or the end of the transaction; the constraint check in SQL standards is completed when the statement is executed

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.