SQL2000 事务回滚问题探讨

复制代码 代码如下:

create procedure test_tran

as

set xact_abort on —–用@@error判断,对于严重的错误,系统根本就不会执行随后对@@error的判断,会直接终止执行。所以设置set xact_abort on 是必要的

begin transaction remoteupdate

insert psn_degree values(22,’test’)

select 1/0

if @@error !=0 begin

rollback transaction remoteupdate

raiserror(‘出错!网络速度慢或断线!’, 16, 16) with seterror

return —没有return 将继续向下执行

end

else begin

commit transaction remoteupdate

end

也可更改为:


复制代码 代码如下:

if @@error !=0 begin

rollback transaction remoteupdate

raiserror(‘出错!网络速度慢或断线!’, 16, 16) with seterror

return —没有return 将继续向下执行

end

commit transaction remoteupdate

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐