sqlserver级联删除
sqlserver怎么实现级联删除啊 求指教 最好来个通俗易懂的例子
我是弄个论坛 在删主题时报错 不能带着回复一起删掉
拜托了
[解决办法]
on delete cascade--级联删除
on update cascade--级联更新
[解决办法]
--级联删除create table ta(id int not null primary key)insert taselect 1create table tb(id int foreign key references ta(id) on delete cascade)insert tbselect 1select * from taselect * from tbdelete taselect * from taselect * from tbdrop table tbdrop table ta
[解决办法]
--->>>>TravyLee生成测试数据if object_id('test')is not nulldrop table testgocreate table test(id int primary key,value varchar(10))goinsert test(id,value)select 1,'test1' union allselect 2,'test2' union allselect 3,'test3' union allselect 4,'test4' union allselect 5,'test5'goif object_id('tbl')is not nulldrop table tblgocreate table tbl(id int foreign key references test(id) on delete cascade --指定级联删除on update cascade, --指定级联更新value varchar(5))goinsert tblselect 1,'true' union allselect 2,'false' union allselect 3,'false' union allselect 4,'true' union allselect 5,'false'godelete from test where value='test2'select * from test/*test数据-------------------------id value1 test13 test34 test45 test5-------------------------tbl数据--------------------------id value1 true3 false4 true5 false*/
[解决办法]