Here is a simple test I coded.
SET XACT_ABORT ON
BEGIN TRANSACTION
GO
CREATE PROCEDURE [usp_MyTest1]
AS
GO
CREATE PROCEDURE [usp_MyTest1]
AS
GO
CREATE PROCEDURE [usp_MyTest2]
AS
GO
COMMIT TRANSACTION
It was my understanding that since I have SET XACT_ABORT ON
, when the second create procedure fails, the entire transaction will roll back. Instead, only things proceeding the error (the first create procedure) are rolled back and the last create procedure executes just fine. I then get a message saying The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
I've seen people have an issue with RAISEERROR, but the documentation for XACT_ABORT says that RAISEERROR does not honnor XACT_ABORT. But this doesn't mention anything about an error such as creating a duplicate procedure not honoring XACT_ABORT.
https://docs.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql
The THROW statement honors SET XACT_ABORT RAISERROR does not. New Applications should use THROW instead of RAISERROR.
This is with SQL Server 2012, if that is relevant.
usp_MyTest2
proceeds in its own transaction, presumably with auto-commit. The transaction does not span from create to commit/rollback from analyzing the text. Also,xact-abort
will abort the batch, butgo
is a batch separator, so last create is in its own batch. – Shannon Severance