Home > Database > Mysql Tutorial > Cascade, NO ACTION, Restrict, SET NULL in MySQL foreign key settings

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

高洛峰
Release: 2016-11-22 11:10:21
Original
1204 people have browsed it

1. Several modes

. Cascade mode

When updating/delete records on the parent table, synchronize update/delete the matching records of the child table

. Set null mode

Update/delete records on the parent table When setting the column of matching records on the child table to null, please note that the foreign key column of the child table cannot be not null

. No action method

If there are matching records in the child table, the correspondence to the parent table is not allowed Candidate keys perform update/delete operations

. Restrict mode

is the same as no action, both of which check foreign key constraints immediately

. Set default mode

When the parent table changes, the child table sets the foreign key column to A default value but Innodb cannot recognize it

2. About the main table, foreign key, and slave table

A person’s identity is unique, but he can do many things. The identity is the master table, and the facts are from the slave table, and from the table The marked id is the user's identity, which is the foreign key of the main table.

For example, customer table and product table

A customer may purchase multiple products. The associated identity is the customer's number or name.

The foreign key is set in the product table.


Summary: The primary key table is the table that is referenced, and the foreign key table is the table that references other tables.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template