Partager via


Using Cursors

ODBC supports a cursor model that allows:

  • Several types of cursors.
  • Scrolling and positioning within a cursor.
  • Several concurrency options.
  • Positioned updates.

ODBC applications rarely declare and open cursors or use any cursor-related Transact-SQL statements. ODBC automatically opens a cursor for every result set returned from an SQL statement. The characteristics of the cursors are controlled by statement attributes set with SQLSetStmtAttr before the SQL statement is executed. The ODBC API functions for processing result sets support the full range of cursor functionality, including fetching, scrolling, and positioned updates.

This is a comparison of how Transact-SQL scripts and ODBC applications work with cursors.

Action Transact-SQL ODBC

Define cursor behavior

Specify through DECLARE CURSOR parameters

Set cursor attributes by using SQLSetStmtAttr

Open a cursor

DECLARE CURSOR OPEN cursor_name

SQLExecDirect or SQLExecute

Fetch rows

FETCH

SQLFetch or SQLFetchScroll

Positioned update

WHERE CURRENT OF clause on UPDATE or DELETE

SQLSetPos

Close a cursor

CLOSE cursor_name DEALLOCATE

SQLCloseCursor

The server cursors implemented in Microsoft SQL Server support the functionality of the ODBC cursor model. The SQL Server Native Client driver uses server cursors to support the cursor functionality of the ODBC API.

For more information, see

Voir aussi

Concepts

SQL Native Client (ODBC)

Autres ressources

CLOSE (Transact-SQL)
Curseurs (moteur de base de données)
DEALLOCATE (Transact-SQL)
DECLARE CURSOR (Transact-SQL)
FETCH (Transact-SQL)
OPEN (Transact-SQL)

Aide et Informations

Assistance sur SQL Server 2005