表 ProductPack (主键ProductPackID)
表 ProductPack_Platform_Link (外键PlatformID,外键ProductPackID)
请问怎么用事务删除ProductPackID=1的数据

解决方案 »

  1.   

    begin tran
    delete from ProductPack where ProductPackID=1
    if @@error=0
      rollback 
    else
      commit tran 
      

  2.   

    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
      

  3.   


    这是最简单方便的方法了。否则先删除ProductPack_Platform_Link ,再删除ProductPack。
      

  4.   

    alter table ProductPack Add constraint fk_Borrow_BorrowNo 
    Foreign key( ProductPackID) references ProductPack_Platform_Link (ProductPackID) 
    on delete cascade  --级联删除
      

  5.   


    alter table ProductPack 
    add constraint ProductPackID
    foreign key(ProductPackID) references ProductPack (ProductPackID)
    on delete cascade
    go