Cursor Types

ODBC, ADO, and DB-Library define four cursor types supported by Microsoft® SQL Server™. With SQL Server version 7.0, the DECLARE CURSOR statement has been extended so you can specify the four cursor types for Transact-SQL cursors. These cursors vary in their ability to detect changes to the result set and in the resources, such as memory and space in tempdb, they consume. A cursor can detect changes to rows only when it attempts to refetch those rows; there is no way for the data source to notify the cursor of changes to the currently fetched rows. The ability of a cursor to detect changes is also influenced by the transaction isolation level.

The four API server cursor types supported by SQL Server are:

Static cursors detect few or no changes but consume relatively few resources while scrolling, although they store the entire cursor in tempdb. Dynamic cursors detect all changes but consume more resources while scrolling, although they make the lightest use of tempdb. Keyset-driven cursors lie in between, detecting most changes but at less expense than dynamic cursors.

Although the database API cursor models consider a forward-only cursor to be a distinct type of cursor, SQL Server does not. SQL Server considers both forward-only and scroll to be options that can be applied to static, keyset-driven, and dynamic cursors.

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.