create procedure test_tran
as
set xact_abort on -----用@@error判断,对于严重的错误,系统根本就不会执行随后对@@error的判断,会直接终止执行。所以设置set xact_abort on 是必要的
BEGIN TRANSACTION RemoteUpdate
insert into test values (2,'23')
--select 1/0
IF @@error !=0 BEGIN
print 'RemoteUpdate'
ROLLBACK TRANSACTION RemoteUpdate
RAISERROR('出错!网络速度慢或断线!', 16, 16) WITH SETERROR
RETURN ---没有return 将继续向下执行
end
else begin
print 'abc'
COMMIT TRANSACTION RemoteUpdate
end
MSSQL事务
猜你喜欢
转载自lanfei.iteye.com/blog/1923826
今日推荐
周排行