The topic describes the DF020 T-SQL code analysis rule.
EXECUTION RULES
The cursor has not been declared.
All statements that reference the cursor by name must have the preceding DECLARE CURSOR statement.
Following this rule helps prevent errors and ensures that cursors are correctly defined and available for use throughout the scope where they are declared. Failure to adhere to this requirement may result in syntax errors or unexpected behavior during query execution.
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId
DECLARE cur CURSOR LOCAL FORWARD_ONLY FOR SELECT
CustomerID
FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId