1、首先打开终端窗口。mysql -uroot -p进入mysql。
3、创建第一个表格,插入数据。
4、创建第二表格,插入数据。
5、创建第三个表格,并且和第一第二个表格关联。
6、INSERT INTO zoo VALUES(1, 1, 2);INSERT INTO zoo VALUES(1, 2, 1);这个时候就能够把他们直接的数据互相关联删除了。比如dog的1和cat的2。
--1 如何删除type的一条记录
go
create proc procDeleteTypeById
@TID int
as
begin
--先删除最外层子表的关联记录 (produnt表)
delete from product where mstid in(select mstid from mstype where stid in(select stid from stype where tid=@TID))
--在删除mstype表中的关联记录
delete from mstype where stid in(select stid from stype where tid=@TID)
--在删除stype表中关联记录
delete from stype where tid=@TID
--最后删除根表记录
delete from [type] where tid=@Tid
end
--2 删除stype表中记录同上
go
create proc procDeleteStype
@STID int
as
begin
--先删除最外层子表的关联记录 (produnt表)
delete from product where mstid in(select mstid from mstype where stid=
@STID)
--在删除mstype表中的关联记录
delete from mstype where stid=@STID
--最后删除根表中的关联记录
delete from stype where stid=@STID
end
以上就是关于mysql中多表关联删除,怎样做谢谢...全部的内容,包括:mysql中多表关联删除,怎样做谢谢...、sql多表删除语句 在线等、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)