Skip to content

SA0152 : THROW statement appears as a transaction name in ROLLBACK TRANSACTION

Not terminating ROLLBACK TRANSACTION with a semicolon before a THROW statement can lead SQL Server to misinterpret THROW as a transaction name.

In T-SQL for SQL Server, a common issue arises when a THROW statement is unintentionally used as a transaction name in a ROLLBACK TRANSACTION statement. This can lead to errors if the ROLLBACK TRANSACTION statement is not properly terminated with a semicolon before the THROW statement.

For example:

-- Example of problematic code without semicolon
BEGIN TRY
BEGIN TRANSACTION
SELECT 1/0
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0 ROLLBACK TRANSACTION
THROW
END CATCH

This example generates a runtime error because SQL Server mistakenly tries to interpret THROW as a transaction name, resulting in a message: “Cannot roll back THROW. No transaction or savepoint of that name was found.”

  • Transaction rollback failures when the semicolon is omitted.

  • Misinterpretation of THROW as a transaction name, causing runtime errors.

Correctly terminate ROLLBACK TRANSACTION statements with a semicolon to prevent SQL Server from interpreting the THROW keyword as a transaction name.

Follow these steps to address the issue:

1.Locate the ROLLBACK TRANSACTION statement within your T-SQL code.

2.Ensure the ROLLBACK TRANSACTION statement is terminated with a semicolon ( ; ) before the THROW statement.

3.Review the surrounding transaction logic to verify transaction consistency and correct error handling.

For example:

BEGIN TRY
BEGIN TRANSACTION;
SELECT 1/0;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;
THROW;
END CATCH

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

8 minutes per issue.

Design Rules, Bugs

THROW (Transact-SQL)

Connect related issue

BEGIN TRY
BEGIN TRANSACTION
SELECT 1/0
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;
THROW
END CATCH
BEGIN TRY
BEGIN TRANSACTION
SELECT 1/0
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0 ROLLBACK TRANSACTION
THROW
END CATCH
  Message Line Column
1 SA0152 : THROW statement will be considered as a transaction name due to a missing semicolon statement terminator after ROLLBACK TRANSACTION statement. 18 30

Analysis Rules