Maison > Article > base de données > MySql的级联关系
数据库表: 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中与关联的内容也删除