复制代码 代码如下:
 
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