Declare cursors - TSQL Tutorial

In this page you can learn how to declare an cursor by reading the syntax and the example.

Declare cursor Syntax:

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


Declare simple cursor example:

DECLARE product_cursor CURSOR
FOR SELECT * FROM model.dbo.products;
OPEN product_cursor
FETCH NEXT FROM product_cursor;

product_idproduct_nameproduct_dspproduct_type
1pro_1product_1AAA