Try cath rollback

Try cath rollback transaction example

BEGIN

    BEGIN TRY --Start the Try Block..

        BEGIN TRANSACTION -- Start the transaction..

        UPDATE MyChecking SET Amount = Amount - @Amount
        WHERE AccountNum = @AccountNum
        UPDATE MySavings SET Amount = Amount + @Amount
        WHERE AccountNum = @AccountNum

        COMMIT TRAN -- Transaction Success!
    END TRY

    BEGIN CATCH
        IF @@TRANCOUNT > 0
            ROLLBACK TRAN --RollBack in case of Error
        
        THROW; -- raise error to the client
    END CATCH

END
GO