Copy codeThe Code is as follows:
Create procedure test_tran
As
Set xact_abort on ----- judge by @ error. For serious errors, the system will not execute the subsequent judgment on @ error, and the execution will be terminated directly. Therefore, it is necessary to set xact_abort on.
Begin transaction RemoteUpdate
Insert psn_degree values (22, 'test ')
Select 1, 1/0
IF @ error! = 0 BEGIN
Rollback transaction RemoteUpdate
RAISERROR ('error! Slow network speed or disconnection! ', 16, 16) WITH SETERROR
RETURN --- no return will continue to be executed
End
Else begin
Commit transaction RemoteUpdate
End
You can also change it:
Copy codeThe Code is as follows:
IF @ error! = 0 BEGIN
Rollback transaction RemoteUpdate
RAISERROR ('error! Slow network speed or disconnection! ', 16, 16) WITH SETERROR
RETURN --- no return will continue to be executed
End
Commit transaction RemoteUpdate