Cursors - SQL

When you write code for a transaction that retrieves a single row of results, you can use a SELECT INTO statement. This is called a singleton SELECT statement.

When you write code for a transaction where the result set includes several rows of data, you must declare and use a cursor. A cursor is a mechanism you can use to fetch rows one at a time.

The four API server cursor types supported by SQL Server are:
  • Static cursors
    Static cursors detect few or no changes but consume relatively few resources while scrolling, although they store the entire cursor in tempdb.
     
  • Dynamic cursors
    Dynamic cursors detect all changes but consume more resources while scrolling, although they make the lightest use of tempdb.
     
  • Keyset-driven cursors
    Keyset-driven cursors lie in between, detecting most changes but at less expense than dynamic cursors.
     
  • Forward-only cursors