Information about cursors

Use sp_cursorinfo to find information about a cursor’s name, its current status, and its result columns. This example displays information about authors_crsr:

sp_cursorinfo 0, authors_crsr
Cursor name ’authors_crsr’ is declared at nesting
    level ’0’.
The cursor id is 327681
The cursor has been successfully opened 1 times
The cursor was compiled at isolation level 1.
The cursor is not open.
The cursor will remain open when a transaction is 
    committed or rolled back.
The number of rows returned for each FETCH is 1.
The cursor is updatable.
There are 3 columns returned by this cursor.
The result columns are:
Name = ’au_id’, Table = ’authors’, Type = ID,
    Length = 11 (updatable)
Name = ’au_lname’, Table = ’authors’, Type = 
    VARCHAR, Length = 40 (updatable)
Name = ’au_fname’, Table = ’authors’, Type = 
    VARCHAR, Length = 20 (updatable)

This example displays information about scrollable cursors:

sp_cursorinfo 0, authors_scrollcrsrCursor name ’authors_scrollcrsr’ is declared at nesting level ’0’.

The cursor is declared as SEMI_SENSITIVE SCROLLABLE cursor.

The cursor id is 786434.

The cursor has been successfully opened 1 times.

The cursor was compiled at isolation level 1.The cursor is currently scanning at a nonzero isolation level.The cursor is positioned on a row.There have been 1 rows read, 0 rows updated and 0 rows deleted through this cursor.The cursor will remain open when a transaction is committed or rolled back.The number of rows returned for each FETCH is 1.The cursor is read only.This cursor is using 19892 bytes of memory.There are 2 columns returned by this cursor.The result columns are:Name = ’au_fname’, Table = ’authors’, Type =VARCHAR, Length = 20 (not updatable)Name = ’au_lname’, Table = ’authors’, Type = VARCHAR, Length = 40 (not updatable)

You can also check the status of a cursor using the @@sqlstatus, @@fetch_status, @@cursor_rows, and @@rowcount global variables. See “Checking cursor status” and “Checking the number of rows fetched”.

See the Reference Manual: Procedures.