Returns information about the cursors that are open in various databases.
ID of the session that holds this cursor.
ID of the cursor object.
Name of the cursor as defined by the user.
Specifies the properties of the cursor. The values of the following properties are concatenated to form the value of this column:
For example, the value returned in this column might be "TSQL | Dynamic | Optimistic | Global (0)".
Handle to the text of the batch that declared the cursor.
Number of characters into the currently executing batch or stored procedure at which the currently executing statement starts. Can be used together with the sql_handle, the statement_end_offset, and the sys.dm_exec_sql_text dynamic management function to retrieve the currently executing statement for the request.
Number of characters into the currently executing batch or stored procedure at which the currently executing statement ends. Can be used together with the sql_handle, the statement_start_offset, and the sys.dm_exec_sql_text dynamic management function to retrieve the currently executing statement for the request.
A sequence number that can be used to distinguish between instances of plans after recompilation.
Timestamp when this cursor was created.
Specifies whether the cursor is open.
Specifies whether the background thread is still asynchronously populating a KEYSET or STATIC cursor.
Specifies whether the cursor was declared by using CURSOR_CLOSE_ON_COMMIT.
1 = Cursor will be closed when the transaction ends.
Returns last fetch status of the cursor. This is the last returned @@FETCH_STATUS value.
Returns information about the size of the fetch buffer.
1 = Transact-SQL cursors. This can be set to a higher value for API cursors.
For FAST_FORWARD and DYNAMIC cursors, it returns 0 if the cursor is not open or if it is positioned before the first row. Otherwise, it returns -1.
For STATIC and KEYSET cursors, it returns 0 if the cursor is not open, and -1 if the cursor is positioned beyond the last row.
Otherwise, it returns the row number in which it is positioned.
Cursor position within the fetch buffer.
Time spent, in microseconds, by the workers executing this cursor.
Number of reads performed by the cursor.
Number of writes performed by the cursor.
Milliseconds since the last query (open or fetch) on this cursor was started.
The following table provides information about the cursor declaration interface and includes the possible values for the properties column.
Cursor was declared by using one of the data access APIs (ODBC, OLEDB).
Cursor was declared by using the Transact-SQL DECLARE CURSOR syntax.
The following table provides information about the cursor type and includes the possible values for the properties column.
Cursor was declared as Keyset.
Cursor was declared as Dynamic.
Cursor was declared as Snapshot or Static.
Cursor was declared as Fast Forward.
The following table provides information about cursor concurrency and includes the possible values for the properties column.
Cursor was declared as read-only.
Cursor uses scroll locks.
Cursor uses optimistic concurrency control.
The following table provides information about cursor scope and includes the possible values for the properties column.
Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created.
Specifies that the scope of the cursor is global to the connection.
A. Detecting old cursors
This example returns information about cursors that have been open on the server longer than the specified time of 36 hours.
SELECT creation_time, cursor_id, name, c.session_id, login_name FROM sys.dm_exec_cursors(0) AS c JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id WHERE DATEDIFF(hh, c.creation_time, GETDATE()) > 36; GO