O'Reilly logo

Microsoft® SQL Server™ 2000 Programming by Example by Carlos Eduardo Rojas, Fernando G. Guerrero

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

Steps to Use Cursors

As shown in Listing 12.8, to use a cursor you must follow this sequence:

  1. Use the DECLARE statement to declare the cursor. This step specifies the type of cursor and the query that defines the data to retrieve. SQL Server creates the memory structures that support the cursor. No data is retrieved yet.

  2. Execute the OPEN statement to open the cursor. In this step, SQL Server executes the query specified in the cursor definition and prepares the data for further navigation.

  3. Execute the FETCH statement to search for rows. In this step, you move the cursor pointer to the required row and, optionally, retrieve column values into variables. Repeat this step as many times as necessary to complete the required task. Optionally, you can ...

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