O'Reilly logo

Microsoft® SQL Server™ 2000 DBA Survival Guide, Second Edition by Mark Spenik, Orryn Sledge

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Cursor

Every cursor must have at least four components. The four key components must follow this order:

1.
DECLARE the cursor
2.
OPEN the cursor
3.
FETCH from the cursor
4.
CLOSE or DEALLOCATE the cursor

Step 1: DECLARE the Cursor

The DECLARE statement contains the user-defined name used to reference the resultset, as well as the SQL SELECT statement that generates the resultset. Think of the DECLARE statement as a temporary table that contains a pointer to your actual data source.

DECLARE Cursor Syntax

The following is the SQL-92 cursor syntax:

DECLARE cursor_name [INSENSITIVE] [SCROLL] CURSOR 
FOR select_statement
[FOR {READ ONLY | UPDATE [OF column_list]}]

The following is the cursor extension syntax. (Note: The syntax that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required