关于表的级联更新和删除



--级联更新和删除
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'的记录也被删除
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值