DF019: The appropriate scroll options of the cursor have not been defined.

Last modified: May 28, 2025

The topic describes the DF019 T-SQL code analysis rule.

Category

PERFORMANCE

Message

The appropriate scroll options of the cursor have not been defined.

Description

No FETCH FIRST/LAST/PRIOR/RELATIVE/ABSOLUTE found, but the cursor is not declared as FORWARD_ONLY or FAST_FORWARD. It is recommended to declare the cursor with the appropriate scroll options.

Additional information

When using Transact-SQL DECLARE cursor extensions:

  • If FORWARD_ONLY or FAST_FORWARD is specified, only the NEXT FETCH option is supported.
  • If neither DYNAMIC nor FORWARD_ONLY nor FAST_FORWARD is defined, and either KEYSET, STATIC, or SCROLL is specified, all FETCH options are supported.
  • DYNAMIC SCROLL cursors support all FETCH options except ABSOLUTE.

Noncompliant code example

DECLARE cur CURSOR LOCAL FOR
SELECT CustomerID FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId

Compliant solution

DECLARE cur CURSOR LOCAL FORWARD_ONLY FOR
SELECT CustomerID FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId