我一直在阅读 MSDN 关于TRY...CATCH
和XACT_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)