Click or drag to resize

SA0026 : Local cursor variable not explicitly deallocated

The topic describes the SA0026 analysis rule.

Message

Local cursor variable not explicitly deallocated

Description

The rule checks if cursor variable is deallocated before the end of the batch using the DEALLOCATE statement.

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

Performance Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 1DECLARE @MyVariable CURSOR
 2
 3DECLARE MyCursor CURSOR FOR
 4SELECT LastName FROM AdventureWorks.Person.Contact
 5
 6SET @MyVariable = MyCursor
 7
 8/* Use DECLARE @local_variable and SET */
 9DECLARE @MyVariable1 CURSOR
10
11SET @MyVariable1 = CURSOR SCROLL KEYSET FOR
12SELECT LastName FROM AdventureWorks.Person.Contact;
13DEALLOCATE MyCursor;
14
15DEALLOCATE @MyVariable1;
16
17-- Uncomment the line below in order to deallocate the cursor variable
18--DEALLOCATE @MyVariable;

Analysis Results

 MessageLineColumn
1SA0026 : Local cursor reference '@MyVariable' not explicitly deallocated.18
See Also

Other Resources