如何级联删除多个表的记录?
现有ABC三个表主键都是snum,现要实现删除A表中某个记录(比如snum为1的记录),如何级联删除BC表中snum为1的记录??有没有这样删的:deleteA,B,Cw...
现有A B C三个表 主键都是snum, 现要实现删除A表中某个记录(比如snum为1的记录),如何级联删除B C表中snum为1的记录??
有没有这样删的: delete A,B,C where..... 展开
有没有这样删的: delete A,B,C where..... 展开
展开全部
如果b,c表的snum是参照A的snum
alter table B
add constraint snum
foreign key(snum) references A(snum)
on delete cascade;
alter table C
add constraint snum
foreign key(snum) references A(snum)
on delete cascade;
delete from A where snum=1;
commit;
alter table B
add constraint snum
foreign key(snum) references A(snum)
on delete cascade;
alter table C
add constraint snum
foreign key(snum) references A(snum)
on delete cascade;
delete from A where snum=1;
commit;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
写成一条语句即可:
DELETE A WHERE snum=1 DELETE B WHERE snum=1 DELETE C WHERE snum=1
DELETE A WHERE snum=1 DELETE B WHERE snum=1 DELETE C WHERE snum=1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
delete A.snum from A
join B
on A.snum=B.snum
join c
on B.snum=A.snum
where snum='1'
试试
join B
on A.snum=B.snum
join c
on B.snum=A.snum
where snum='1'
试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询