.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sharon Maxwell

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Cursors use in SQL Server

Posted By:Shashi Ray       Posted Date: December 29, 2008    Points: 25    Category: DataBase    URL: http://www.dotnetspark.com  

A cursor is a database object that helps in accessing and manipulating data in given result set.

The main advantage is that we can process the data row-by -row.

There are four types' cursors.

1. Static: It always displays the result set as it was when the cursor opened. Static cursors are always read-only.

2. Dynamic: Dynamic cursors are opposite of static cursors. It refers all changes made to the rows in their result set when scrolling through the cursor.

3. Forward- Only: The forward only cursor does not support; it supports only fetching the rows serially from the start to end of the cursors.

4. Keyset-driven: The keyset is the set of key values from all the rows that qualified for the select statement at the time the cursor was opened.


*Declare a Cursor

Exec SQL DECLARE c1 CURSOR FOR Select name, dept from table1 where job='Mgr' END-EXEC.;

*Open the Cursor


*Fetch rows from the 'table1' table

Perform Fetch-Loop thru End-Fetch-Loop until SQLCODE not equal 0;

*Close the Cursor


MOVE "CLOSE CURSOR" to errloc.


Shashi Ray

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend