Transact-SQL Cursor Syntax

A number of commands and functions relate to cursors. Table 14.2 summarizes them. The following subsections cover these commands in more detail.

Table 14.2. Transact-SQL Cursor Commands and Functions
Command or FunctionPurpose
DECLARE CURSORDefines a cursor
OPENOpens a cursor so that data may be retrieved from it
FETCHFetches a single row from the cursor
CLOSECloses the cursor, leaving intact the internal structures that service it
DEALLOCATEFrees the cursor's internal structures
@@CURSOR_ROWSReturns the number of rows exposed by the cursor
@@FETCH_STATUSIndicates the success or failure of the last FETCH
CURSOR_STATUSReports status information for cursors and cursor variables


DECLARE CURSOR defines cursors. There ...

Get Guru's Guide to SQL Server Architecture and Internals, The now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.