国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长治县| 永仁县| 柘荣县| 兴安盟| 合阳县| 呈贡县| 平顺县| 丹棱县| 舟曲县| 家居| 阜宁县| 瑞金市| 宁波市| 古丈县| 通辽市| 密山市| 界首市| 陕西省| 年辖:市辖区| 桃园县| 棋牌| 阿克陶县| 阜平县| 保康县| 竹北市| 梁平县| 白水县| 手游| 乌鲁木齐县| 旅游| 屯昌县| 嘉兴市| 乐都县| 六安市| 浮山县| 镇坪县| 双城市| 建水县| 鄢陵县| 阿图什市| 石棉县|