SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement

The topic describes the SA0265 analysis rule.

Message

COMMIT statement without corresponding BEGIN TRANSACTION statement

Description

The rule checks T-SQL code and reports COMMIT statements, which have no corresponding BEGIN TRANSACTION statements.

Issuing a COMMIT TRANSACTION when @@TRANCOUNT is zero results in an error.

Scope

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

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, Bugs

Additional Information
Example Test Script
SQL
 1BEGIN TRANSACTION -- @@TRANCOUNT is 1
 2BEGIN TRANSACTION -- @@TRANCOUNT is 2
 3
 4COMMIT TRANSACTION -- @@TRANCOUNT is 1
 5COMMIT TRANSACTION -- @@TRANCOUNT is 0
 6COMMIT TRANSACTION -- error
 7
 8BEGIN TRANSACTION -- @@TRANCOUNT is 1
 9BEGIN TRANSACTION -- @@TRANCOUNT is 2
10
11COMMIT TRANSACTION -- @@TRANCOUNT is 1
12COMMIT TRANSACTION -- @@TRANCOUNT is 0
13COMMIT TRANSACTION -- error
14COMMIT TRANSACTION -- error

Analysis Results

  Message Line Column
1 SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement. 6 0
2 SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement. 13 0
3 SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement. 14 0
See Also

Other Resources