set xact_abort on
begin tran
   update..1
   insert..2
   delete..3
commit tran
set xact_abort off1,2,3任一失败就立即自动回滚

解决方案 »

  1.   

    @@ERROR
    返回最后执行的 Transact-SQL 语句的错误代码。
      

  2.   

    例:create table Table1 (a int)
    go
    begin tran
      insert table1 values(1)               ----这句是对的
      insert table1 values('aaa')           ----这句由于类型不一样将报错
    commit transelect * from table1         ------结果是两句都没插入!应为他们是一个事务