MySql的级联关系

原创
2016-06-07 15:39:55 860浏览

数据库表: 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:


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 ACTION时

与上述一样

SET NULL时

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

CASCADE时

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


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。