相关疑难解决方法(0)

当 XACT_ABORT 设置为 ON 时,在什么情况下可以从 CATCH 块内部提交事务?

我一直在阅读 MSDN 关于TRY...CATCHXACT_STATE

它有以下示例,用于XACT_STATE在构造CATCH块中TRY…CATCH确定是提交还是回滚事务:

USE AdventureWorks2012;
GO

-- SET XACT_ABORT ON will render the transaction uncommittable
-- when the constraint violation occurs.
SET XACT_ABORT ON;

BEGIN TRY
    BEGIN TRANSACTION;
        -- A FOREIGN KEY constraint exists on this table. This 
        -- statement will generate a constraint violation error.
        DELETE FROM Production.Product
            WHERE ProductID = 980;

    -- If the delete operation succeeds, commit the transaction. The CATCH
    -- block will not execute. …
Run Code Online (Sandbox Code Playgroud)

sql-server-2008 sql-server

17
推荐指数
4
解决办法
8424
查看次数

标签 统计

sql-server ×1

sql-server-2008 ×1