Using Cursors

ODBC supports a cursor model that allows:

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 ODBC driver uses server cursors to support the cursor functionality of the ODBC API.

See Also
SQLSetStmtAttr OPEN
Cursors FETCH
SQLFetchScroll CLOSE
SQLCloseCursor DEALLOCATE
DECLARE CURSOR  

  


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