0--Procedurecalledwhenthereis--anactivetransaction.--Createasavepointtobeable--torollbackonlytheworkdone--intheprocedureifthereisan--error.SAVE" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

SQL Server 事務嵌套

系統 2023 0
原文: SQL Server 事務嵌套

示例代碼:

      
        DECLARE
      
      
        @TranCounter
      
      
        INT
      
      
        ;




      
      
        SET
      
      
        @TranCounter
      
      
        =
      
      
        @@TRANCOUNT
      
      
        ;


      
      
        IF
      
      
        @TranCounter
      
      
        >
      
      
        0
      
      
        --
      
      
         Procedure called when there is
      
      
        --
      
      
         an active transaction.
      
      
        --
      
      
         Create a savepoint to be able
      
      
        --
      
      
         to roll back only the work done
      
      
        --
      
      
         in the procedure if there is an
      
      
        --
      
      
         error.
      
      
        SAVE
      
      
        TRANSACTION
      
      
         ProcedureSave;


      
      
        ELSE
      
      
        --
      
      
         Procedure must start its own
      
      
        --
      
      
         transaction.
      
      
        BEGIN
      
      
        TRANSACTION
      
      
        ;


      
      
        --
      
      
         Modify database.
      
      
        BEGIN
      
      
         TRY



    
      
      
        /*
      
      
        *

        Write your T-SQL here...

    *
      
      
        */
      
      
        --
      
      
         Get here if no errors; must commit
      
      
        --
      
      
         any transaction started in the
      
      
        --
      
      
         procedure, but not commit a transaction
      
      
        --
      
      
         started before the transaction was called.
      
      
        IF
      
      
        @TranCounter
      
      
        =
      
      
        0
      
      
        --
      
      
         @TranCounter = 0 means no transaction was
      
      
        --
      
      
         started before the procedure was called.
      
      
        --
      
      
         The procedure must commit the transaction
      
      
        --
      
      
         it started.
      
      
        COMMIT
      
      
        TRANSACTION
      
      
        ;


      
      
        END
      
      
         TRY


      
      
        BEGIN
      
      
         CATCH

    
      
      
        --
      
      
         An error occurred; must determine
      
      
        --
      
      
         which type of rollback will roll
      
      
        --
      
      
         back only the work done in the
      
      
        --
      
      
         procedure.
      
      
        IF
      
      
        @TranCounter
      
      
        =
      
      
        0
      
      
        --
      
      
         Transaction started in procedure.
      
      
        --
      
      
         Roll back complete transaction.
      
      
        ROLLBACK
      
      
        TRANSACTION
      
      
        ;

    
      
      
        ELSE
      
      
        --
      
      
         Transaction started before procedure
      
      
        --
      
      
         called, do not roll back modifications
      
      
        --
      
      
         made before the procedure was called.
      
      
        IF
      
       XACT_STATE() 
      
        <>
      
      
        -
      
      
        1
      
      
        --
      
      
         If the transaction is still valid, just
      
      
        --
      
      
         roll back to the savepoint set at the
      
      
        --
      
      
         start of the stored procedure.
      
      
        ROLLBACK
      
      
        TRANSACTION
      
      
         ProcedureSave;

            
      
      
        --
      
      
         If the transaction is uncommitable, a
      
      
        --
      
      
         rollback to the savepoint is not allowed
      
      
        --
      
      
         because the savepoint rollback writes to
      
      
        --
      
      
         the log. Just return to the caller, which
      
      
        --
      
      
         should roll back the outer transaction.
      
      
        --
      
      
         After the appropriate rollback, echo error
      
      
        --
      
      
         information to the caller.
      
      
        DECLARE
      
      
        @ErrorMessage
      
      
        NVARCHAR
      
      (
      
        4000
      
      
        );

    
      
      
        DECLARE
      
      
        @ErrorSeverity
      
      
        INT
      
      
        ;

    
      
      
        DECLARE
      
      
        @ErrorState
      
      
        INT
      
      
        ;



    
      
      
        SELECT
      
      
        @ErrorMessage
      
      
        =
      
      
         ERROR_MESSAGE();

    
      
      
        SELECT
      
      
        @ErrorSeverity
      
      
        =
      
      
         ERROR_SEVERITY();

    
      
      
        SELECT
      
      
        @ErrorState
      
      
        =
      
      
         ERROR_STATE();



    
      
      
        RAISERROR
      
       (
      
        @ErrorMessage
      
      , 
      
        @ErrorSeverity
      
      , 
      
        @ErrorState
      
      
        );




      
      
        END
      
       CATCH
    

?

SQL Server 事務嵌套


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 免费的毛片视频 | 日韩伦理一区二区 | 久久99精品国产99久久 | 91久久综合九色综合欧美98 | 美女视频黄的全i免费 | 日本黄 色 成 年 人免费观看 | 伊人成人在线视频 | 国产精品久久久久久久hd | 久久福利青草精品资源站免费 | 激情网站视频 | 网曝门精品国产事件在线观看 | 久久综合伊人 | 午夜性盈盈 | 日韩欧美福利 | 久久精品国产免费观看99 | 久久手机免费视频 | 成人看片黄a毛片 | 国产中文字幕视频在线观看 | 国产综合成人亚洲区 | 成人最新午夜免费视频 | 久久久久久99精品 | 免费爱爱视频网站 | 亚洲精品无码不卡在线播放he | 国产动作大片中文字幕 | 日本一级高清不卡视频在线 | 亚洲国产精选 | 福利在线国产 | 国产福利小视频在线观看 | 国产美女久久久久 | 毛片大全免费观看 | 一区二区三区精品国产欧美 | 色综合久久久久综合99 | 久久综合九色综合97伊人麻豆 | 成人 亚洲 成人影院 | 日韩欧美亚洲综合久久影院d3 | 91精品论坛 | 欧美xxxxx九色视频免费观看 | 曰本毛片| 国内精品福利视频 | 日韩中文字幕一区二区不卡 | 四虎影视永久在线精品免费 |