Click or drag to resize

SA0256 : A cursor with the same name is declared earlier. Avoid reusing cursor names

The topic describes the SA0256 analysis rule.

Message

A cursor with the same name is declared earlier. Avoid reusing cursor names

Description

The rule checks T-SQL code for cursor declarations and reports when a cursor name is declared more than once in the current scope.

It is not a good practice to re-declare cursor and should be avoided.

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
 1DECLARE vend_cursor CURSOR FOR SELECT * FROM Purchasing.Vendor
 2
 3FETCH NEXT FROM vend_cursor
 4
 5OPEN vend_cursor
 6
 7CLOSE vend_cursor
 8
 9DEALLOCATE vend_cursor
10
11DECLARE vend_cursor CURSOR FOR SELECT * FROM Purchasing.Vendor

Analysis Results

 MessageLineColumn
1SA0256 : The declared cursor name [vend_cursor] is used in a previous declaration. Avoid reusing cursor names.118
See Also

Other Resources