SQL 存储过程中事务回滚
在事务语句最前面加上 set xact_abort on
1 GO 2 SET QUOTED_IDENTIFIER OFF 3 GO 4 ALTER PROCEDURE [dbo].[test] 5 @a int, 6 @b int, 7 @c int, 8 @d int, 9 @e int, 10 @f int 11 AS 12 13 set xact_abort on 14 begin tran 15 insert into testtb values(@a,@b,@c,@d) 16 insert into test4 values(@e,@f) 17 commit tran
当xact_abort选项为on时,SQL Server在遇到错误时会终止执行并rollback整个事务。