alter procedure sp_test_tran
as
begin
SET XACT_ABORT ON --开启全部回滚(包括嵌套事务),关闭不会滚嵌套事务
----begin tran
insert into test_tran191 values ('one')
exec [temperp].paxbase.dbo.sp_test_tran '1234'
insert into test_t1(id) values ('two')
if @@error =0
begin
print 'commit tran '
commit tran
end
else
begin
print 'rollback tran '
rollback tran
end
end
该博客内容涉及SQL事务处理,使用了ALTER PROCEDURE创建存储过程,并在其中开启和管理事务。通过插入数据并调用另一个存储过程,然后根据@@ERROR检查错误来决定是提交还是回滚事务。
2856

被折叠的 条评论
为什么被折叠?



