Home > Database > Mysql Tutorial > Mysql中的Cascade,NO ACTION,Restrict,SET NULL_MySQL

Mysql中的Cascade,NO ACTION,Restrict,SET NULL_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:30:55
Original
977 people have browsed it

bitsCN.com

Mysql中的Cascade,NO ACTION,Restrict,SET NULL

 

外键约束对子表的含义: 

如果在父表中找不到候选键,则不允许在子表上进行insert/update 

 

外键约束对父表的含义: 

在父表上进行update/delete以更新或删除在子表中有一条或多条对应匹配行的候选键时,父表的行为取决于:在定义子表的外键时指定的on update/on delete子句, InnoDB支持5种方式, 分列如下 :

 

cascade方式 

在父表上update/delete记录时,同步update/delete掉子表的匹配记录 

On delete cascade从mysql3.23.50开始可用; on update cascade从mysql4.0.8开始可用 

 

set null方式 

在父表上update/delete记录时,将子表上匹配记录的列设为null 

要注意子表的外键列不能为not null 

On delete set null从mysql3.23.50开始可用; on update set null从mysql4.0.8开始可用 

 

No action方式 

如果子表中有匹配的记录,则不允许对父表对应候选键进行update/delete操作 

这个是ANSI SQL-92标准,从mysql4.0.8开始支持 

 

Restrict方式 

同no action, 都是立即检查外键约束 

 

 

bitsCN.com
Related labels:
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
Latest Issues
php - pdo fails to insert data into database?
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
mongodb - How to batch insert data in mongoose?
From 1970-01-01 08:00:00
0
0
0
python - mysql insert error in multithreading
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template