Mysqlinnodb foreign key _ MySQL

Source: Internet
Author: User
Mysqlinnodb foreign key Mysql foreign key

BitsCN.com

Mysql innodb foreign key

Meanings of foreign key constraints on subtables:

If no candidate key is found in the parent table, insert/update is not allowed in the child table.

Description of the foreign key constraint on the parent table:

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:

. Cascade method

When updating/deleting records in the parent table, synchronize update/delete matching records in the child table

On delete cascade is available from mysql3.23.50; on update cascade is available from mysql4.0.8

. Set null

When updating/deleting records in the parent table, set the columns of matched records in the child table to null.

Note that the foreign key column of the sub-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 method

If the child table has matched records, the update/delete operation on the candidate keys corresponding to the parent table is not allowed.

This is ANSI SQL-92 standard, supported since mysql4.0.8

. Restrict method

The same as no action, both check foreign key constraints immediately

. Set default mode

The parser recognizes this action, but Innodb cannot recognize it and doesn't know what it means...

Note: trigger is not affected by the cascade action of the foreign key, that is, trigger is not released.

BitsCN.com

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.