Home > Database > Mysql Tutorial > MySql的级联关系

MySql的级联关系

WBOY
Release: 2016-06-07 15:39:55
Original
1209 people have browsed it

数据库表: class: teacher class与teacher是一对多 执行SQL: delete from teacher where t_id=1; 数据库的级联设置为: RESTRICT时 报错:a foreign key constraint fails 外键关联 这时需要先将class update class set teacher_id=null where c_id=1 NO A

数据库表:

class:

MySql的级联关系

teacher

MySql的级联关系

class与teacher是一对多

执行SQL:

delete from teacher where t_id=1;

数据库的级联设置为:

RESTRICT时   

报错:a foreign key constraint fails 外键关联 这时需要先将class

update class set teacher_id=null where c_id=1

NO ACTION时

与上述一样

SET NULL时

teacher 删除,class中的teacher_id自动设置为null

CASCADE时

teacher中的内容删除,class中与关联的内容也删除


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