Microsoft SQL ServerCursors

Download Microsoft SQL Server for free

Syntax

  • DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ]
    • [ FORWARD_ONLY | SCROLL ]
      [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
      [ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
      [ TYPE_WARNING ]
    • FOR select_statement
    • [ FOR UPDATE [ OF column_name [ ,...n ] ] ]

Remarks

Normally you would want to avoid using cursors as they can have negative impacts on performance. However in some special cases you may need to loop through your data record by record and perform some action.

Related Examples

Basic Forward Only Cursor