begin tran delete from ProductPack where ProductPackID=1 if @@error=0 rollback else commit tran
begin tran delete ProductPack_Platform_Link where ProductPackID=1 if @@error<>0 rollback tran else begin delete ProductPack where ProductPackID=1 if @@error<>0 rollback tran else commit tran end
delete from ProductPack where ProductPackID=1
if @@error=0
rollback
else
commit tran
delete ProductPack_Platform_Link where ProductPackID=1
if @@error<>0
rollback tran
else
begin
delete ProductPack where ProductPackID=1
if @@error<>0
rollback tran
else
commit tran
end
这是最简单方便的方法了。否则先删除ProductPack_Platform_Link ,再删除ProductPack。
Foreign key( ProductPackID) references ProductPack_Platform_Link (ProductPackID)
on delete cascade --级联删除
alter table ProductPack
add constraint ProductPackID
foreign key(ProductPackID) references ProductPack (ProductPackID)
on delete cascade
go