>  기사  >  데이터 베이스  >  MySql的级联关系

MySql的级联关系

WBOY
WBOY원래의
2016-06-07 15:39:551127검색

数据库表: 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中与关联的内容也删除


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.