https://www.douban.com/note/559596669/
Format is similar to
CREATE PROCEDURE Yourprocedure
As
BEGIN
SET NOCOUNT on;
Begin TRY---------------------Start catching exceptions
BEIN TRAN------------------Start a transaction
UPDATE A SET a.names = b.names from table 1 as A INNER JOIN table 2 as B on a.id = b.ID
UPDATE A SET a.names = b.names from table 1 as A INNER JOIN table 2 as B on a.test = B.test
Commit TRAN-------COMMIT Transaction
End TRY-----------Ending catch exception
BEGIN catch------------An exception is caught
If @ @TRANCOUNT > 0---------------Determine if there is a transaction
BEGIN
ROLLBACK TRAN----------ROLLBACK TRANSACTION
END
EXEC yourlogerrorprocedure-----------Record error message when the stored procedure is executed, custom
End CATCH--------Ending exception handling
END
Using transactions with catch exceptions in SQL Server stored procedures