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條評論
主站蜘蛛池模板: 天天久久综合 | 久久一本一区二区三区 | 国产日韩欧美在线观看免费视频 | 最新亚洲精品国自产在线观看 | 国产国产精品人在线观看 | 深夜福利剧场 | 欧美综合天天夜夜久久 | 日韩欧美精品一区二区三区 | 日韩免费高清一级毛片在线 | 国产在线视频www色 国产在线视频凹凸分类 | 色综合亚洲天天综合网站 | 视频一区在线播放 | 四虎影永久在线观看精品 | 天天操穴 | 亚洲人成影院在线高清 | 久久视频免费 | 国产一区亚洲欧美成人 | 中文字幕一区二区三区免费视频 | 国产欧美精品午夜在线播放 | 亚洲国产日韩欧美一区二区三区 | 国产亚洲精品久久麻豆 | 97夜夜澡人人爽人人免费 | 99热久久国产精品 | 一 级 黄 中国色 片 | 午夜免费一级片 | 激情五月婷婷基地 | 欧美高清不卡午夜精品免费视频 | 国产日韩欧美在线一区二区三区 | 香蕉视频看片 | 精品日产一区二区 | 日韩免费大片 | 免费日本黄色网址 | 日韩免费一级毛片 | 12345国产精品高清在线 | 亚洲国产一区二区三区最新 | 亚洲精品乱码久久久久久 | 四虎影院在线网址 | 5151四虎永久在线精品免费 | 99在线免费观看视频 | 国产精品1区2区3区 国产精品1区2区3区在线播放 | 亚洲综合色视频在线观看 |