create procedure test_tran as set xact_abort on -----用@@error判斷,對于嚴重的錯誤,系統(tǒng)根本就不會執(zhí)行隨后對@@error的判斷,會直接終止執(zhí)行。所以設置set xact_abort on 是必要的 BEGIN TRANSACTION RemoteUpdate insert psn_degree values(22,'test') select 1/0 IF @@error !=0 BEGIN ROLLBACK TRANSACTION RemoteUpdate RAISERROR('出錯!網(wǎng)絡速度慢或斷線!', 16, 16) WITH SETERROR RETURN ---沒有return 將繼續(xù)向下執(zhí)行 end else begin COMMIT TRANSACTION RemoteUpdate end
也可更改為:
復制代碼 代碼如下:
IF @@error !=0 BEGIN ROLLBACK TRANSACTION RemoteUpdate RAISERROR('出錯!網(wǎng)絡速度慢或斷線!', 16, 16) WITH SETERROR RETURN ---沒有return 將繼續(xù)向下執(zhí)行 end COMMIT TRANSACTION RemoteUpdate