5.9. CURSORS

A cursor is a named SELECT statement in which the result set is accessed one row at time. The cursor may be moved, often in a loop, to a different row in the result set using the fetch statement as follows.

FETCH [ NEXT | PREV | FIRST | LAST ]

Cursors may be specified as read only or updateable as well as forward only or scrollable (can move forward and backward) and may be specified to have other features.

Note: Cursors are often considered to be inefficient and best avoided if possible. The interested reader is referred to Ben-Gan and Moreau[3] on best use of cursors. They open with the following advice.

[3] Ben-Gan 2000, p. 553.

In most cases where cursors are being used, they are not really necessary. You should look upon cursors ...

Get Transact-SQL Desk Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.