SQL Flow Field Guide

Cursors

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

none (documentation, rules or examples)

What changes

Input
none
Output or change
none

Syntax at a glance

n/a (reference page)

Work example

A task appears to require row-by-row work and needs a safe cursor lifecycle review.

Try a set-based query first. If a cursor remains, use the smallest scope and close it on every error path.

Check your work Cursors. Each input row is handled once and the cursor is closed and deallocated on every exit path.

Open Microsoft Learn for full syntax, permissions, and details for your version.