Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 4.27 KB

File metadata and controls

73 lines (53 loc) · 4.27 KB
title Using Cursors (ODBC) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service database-engine, sql-database, sql-data-warehouse, pdw
ms.reviewer
ms.technology native-client
ms.topic reference
helpviewer_keywords
SQL Server Native Client ODBC driver, cursors
ODBC cursors, about ODBC cursors
ODBC applications, cursors
cursors [ODBC]
ODBC cursors
ms.assetid 51322f92-0d76-44c9-9c33-9223676cf1d3
author markingmyname
ms.author maghan
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current

Using Cursors (ODBC)

[!INCLUDEappliesto-ss-asdb-asdw-pdw-md]

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 [!INCLUDEtsql] 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 [!INCLUDEtsql] scripts and ODBC applications work with cursors.

Action [!INCLUDEtsql] 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 [!INCLUDEssNoVersion] support the functionality of the ODBC cursor model. The [!INCLUDEssNoVersion] Native Client driver uses server cursors to support the cursor functionality of the ODBC API.

In This Section

See Also

SQL Server Native Client (ODBC)
CLOSE (Transact-SQL)
Cursors
DEALLOCATE (Transact-SQL)
DECLARE CURSOR (Transact-SQL)
FETCH (Transact-SQL)
OPEN (Transact-SQL)