Click or drag to resize

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, New Rules

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

 MessageLineColumn
1SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement.60
2SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement.130
3SA0265 : COMMIT statement without corresponding BEGIN TRANSACTION statement.140
See Also

Other Resources