set xact_abort on begin tran update a ... update b ... commit tran
begin tran begin try update tb1... update tb2... IF @@trancount>0 commit tran end try begin catch IF @@trancount>0 rollback tran end catch
set xact_abort on begin tran update ... update ... commit tran--当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚。 --当 SET XACT_ABORT 为 OFF 时,有时只回滚产生错误的 Transact-SQL 语句,而事务将继续进行处理。 --如果错误很严重,那么即使 SET XACT_ABORT 为 OFF,也可能回滚整个事务。
begin tran
update a ...
update b ...
commit tran
begin try
update tb1...
update tb2...
IF @@trancount>0
commit tran
end try
begin catch
IF @@trancount>0
rollback tran
end catch
begin tran
update ...
update ...
commit tran--当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚。
--当 SET XACT_ABORT 为 OFF 时,有时只回滚产生错误的 Transact-SQL 语句,而事务将继续进行处理。
--如果错误很严重,那么即使 SET XACT_ABORT 为 OFF,也可能回滚整个事务。