SA0107 : Avoid using procedural logic with a cursor

The topic describes the SA0107 analysis rule.

Message

Avoid using procedural logic with a cursor

Description

The rule identifies CURSOR usage inside the code and notifies for cursor declarations.

How to fix

Review your code and consider using a set-based solution instead of the cursor/iterative solution for the given task.

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.

Effort To Fix
3 hours per issue.
Categories

Design Rules, Bugs

Additional Information
Example Test SQL
SQL
1DECLARE vend_cursor CURSOR
2    FOR SELECT BusinessEntityID, Name, CreditRating FROM Purchasing.Vendor
3
4OPEN vend_cursor
5
6FETCH NEXT FROM vend_cursor;

Analysis Results
  Message Line Column
1 SA0107 : Avoid using procedural logic with a cursor. 1 8
See Also

Other Resources