what is a cursor and what is its use?

Answer Posted / praveen singh

A cursor is a set of rows together with a pointer that
identifies a current row.

In other word, Cursor is a database object used by
applications to manipulate data in a set on a row-by-row
basis, its like recordset in the ASP and visual basic.


DECLARE @fName varchar(50), @lName varchar(50)

DECLARE cursorName CURSOR -- Declare cursor

LOCAL SCROLL STATIC

FOR

Select firstName, lastName FROM myTable

OPEN cursorName -- open the cursor

FETCH NEXT FROM cursorName

INTO @fName, @lName

PRINT @fName + ' ' + @lName -- print the name

WHILE @@FETCH_STATUS = 0

BEGIN

FETCH NEXT FROM cursorName

INTO @fName, @lName

PRINT @fName + ' ' + @lName -- print the name

END



CLOSE cursorName -- close the cursor

DEALLOCATE cursorName -- Deallocate the cursor

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define msdb database?

785


What is sql server profiler trace data file?

783


Explain about builtinadministrator?

768


Tell me the use of keyword with encryption. Create a store procedure with encryption?

747


How to skip remaining statements in a loop block using continue statements?

743






How to restore performance issues and how to check?

1708


Why and when do stored procedure recompile?

705


What are the advantages of user-defined functions over stored procedures in sql server?

663


Write a query to include a constraint, to check whether the employee salary is greater than 5000?

1345


What are drillthrough reports?

128


How to get a list of columns using the "sys.columns" view in ms sql server?

738


how do you determine the Load performance of any query in sql server {example how do u determine performance of a select stmnt which returns Dynamically many no of records ... some times 100,1000,10000 etc., }

2030


What is a livelock?

719


What is the difference between commit and rollback?

671


What is the difference between a unique key and primary key?

681