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

참고 항목

개념

SQL Native Client (ODBC)

관련 자료

CLOSE(Transact-SQL)
커서(데이터베이스 엔진)
DEALLOCATE(Transact-SQL)
DECLARE CURSOR(Transact-SQL)
FETCH(Transact-SQL)
OPEN(Transact-SQL)

도움말 및 정보

SQL Server 2005 지원 받기