what is a cursor and what is its use?

Answers were Sorted based on User's Feedback



what is a cursor and what is its use?..

Answer / 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

what is a cursor and what is its use?..

Answer / ramesh

when we execute any query its return result set. directly
to work on result set we use cursors.

but right now no one is supporting cursors.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Can we use where clause with group by?

0 Answers  


What is the difference between in and exists. Ex: select * from emp where empno in(....) and select * from emp where empno exists(....) What is the difference between a Join and Union and Union and UnionAll.

5 Answers   ABC, Accenture,


How to create hyperlink from returned sql query ?

0 Answers   MCN Solutions,


What type of locking occurs during the snapshot generation? : sql server replication

0 Answers  


List all the types of user-defined functions?

0 Answers  






Give some Scenario for Non Clusterd index? Can we write system defined functions in side The Function? Wat is the Unique Datatype?

0 Answers   Value Labs,


Why Master database is required?

0 Answers   Abacus,


Can group by be used without aggregate functions?

0 Answers  


What is the difference between varchar and nvarchar?

0 Answers  


What are the instances when triggers are appropriate?

0 Answers  


What is a fill factor?

0 Answers  


What is sql server locking?

0 Answers  


Categories