国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SQL Server 事務嵌套

2024-08-31 00:55:14
字體:
來源:轉載
供稿:網友
SQL Server 事務嵌套 2014-11-06 13:33 by 杰克小薛, ... 閱讀, ... 評論, 收藏, 編輯

示例代碼:

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 TRYBEGIN 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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙湾县| 南通市| 鄂托克旗| 苏尼特左旗| 临西县| 奎屯市| 安平县| 德昌县| 灵丘县| 临江市| 广东省| 宣汉县| 瑞丽市| 班戈县| 万荣县| 闻喜县| 赤城县| 绥棱县| 巴里| 屯留县| 新安县| 宣汉县| 滨海县| 湘阴县| 襄垣县| 新昌县| 塔城市| 吴桥县| 长丰县| 涿鹿县| 江城| 丰顺县| 朝阳市| 马龙县| 永寿县| 洛浦县| 巴彦县| 浦县| 岫岩| 绍兴县| 山阴县|