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

We are updating a field in sql and alter the row also.after giving the commit command the system is crashed.what will happen to the commands given,whether it will update and alter the table or not?

0 Answers   Amdocs, Apps Associates,


How to delete duplicate rows from table except one?

0 Answers  


What is awe?

0 Answers  


What is importing utility?

0 Answers  


Why I am getting this error when renaming a database in ms sql server?

0 Answers  






What is the use of CASCADE CONSTRAINTS?

3 Answers  


How do I install sql server?

0 Answers  


What are the components of sql server service broker?

0 Answers  


Which is the main third-party tool used in sql server?

0 Answers  


What is isolation levels?

0 Answers  


What is user-defined function?

0 Answers  


Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table?

5 Answers   eFunds,


Categories