--级联更新和删除
create table T1
(
sno varchar(10) not null primary key,
sname varchar(20),
sage int
)
create table T2
(sno varchar(10) not null references t1(sno) on delete cascade on update cascade,--当引用表的对应字段发生更新或者删除操作时,从表对应记录也会更新或者删除
grade int
)
--向T1表中插入数据
insert into t1
select '1001','aa',25 union all
select '1002','bb',24 union all
select '1003','cc',22
--向T2表中插入数据
insert into t2
select '1001',80 union all
select '1002',90 union all
select '1003',86
--更新t1中学号为'1001'的记录
update t1 set sno='1004' where sno='1001'
结果:
t2中学号为'1001'的记录也发生更新
--删除t1中学号为'1004'的记录
delete from t1 where sno='1004'
结果:
t2中学号为'1004'的记录也被删除