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
也可更改為:
復制代碼 代碼如下:www.CuoXIn.com
IF @@error !=0 BEGIN ROLLBACK TRANSACTION RemoteUpdate RAISERROR('出錯!網絡速度慢或斷線!', 16, 16) WITH SETERROR RETURN ---沒有return 將繼續向下執行 end COMMIT TRANSACTION RemoteUpdate