Live2D 看板娘 / Demo

sql 事务的用法(BEGIN TRAN COMMIT TRAN )

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE XXX
    @userId INT
AS
BEGIN
    IF @userId IS NULL RETURN 0

    BEGIN TRY
        BEGIN TRAN 
        ---------------------------------------------
        DECLARE @result INT 
        ---------------------------------------------
        EXEC @result = XXX @userId

        IF @result <= 0 
        BEGIN 
            ROLLBACK TRAN 
            RETURN @result
        END 
        ---------------------------------------------
        EXEC @result = XXX @userId

        IF @result <= 0
        BEGIN 
            ROLLBACK TRAN 
            RETURN @result
        END 
        
        COMMIT TRAN 
        RETURN @userId
    END TRY
    BEGIN CATCH
        ROLLBACK TRAN 
        SELECT '检测用户账户时发生异常'
        PRINT ERROR_MESSAGE()
        RETURN -209
    END CATCH
END

 

posted @ 2016-11-18 14:09  MChuang  阅读(1765)  评论(0编辑  收藏  举报