A cursor is a symbolic name that an application attaches to a select statement. The statement can be executed and its result set manipulated by performing operations on the cursor.
Cursors support the following operations:
Declare – create a new cursor by giving it a name and defining its query.
Set cursor rows – specify the number of rows from the result table to be returned with each fetch operation.
Open – execute the cursor’s query and prepare it for fetch operations.
Fetch – retrieve rows from the cursor, which must be open. Each fetch operation retrieves a number of rows in the query’s result table (with the number defined by the “set cursor rows” operation).
Update – modify the values in a fetched row. The update affects the tables from which the row was selected.
Delete – remove a fetched row from an underlying table.
Close – ready the cursor to be either reopened or deallocated.
Deallocate – free the cursor’s resources.
In an Adaptive Server client application, cursors can either be created and manipulated with language commands or with ct_cursor commands. Cursors created using Transact-SQL language commands are called language cursors. Cursors created with ct_cursor commands are called Client-Library cursors. Table 7-1 compares the two types of cursors.