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

What is the difference between inner join and equi join?

0 Answers  


what is package configuration variable?How to change file name in folder dynamically?Plz help me

1 Answers  


What is the purpose of indexing?

0 Answers  


Why the trigger fires multiple times in single login?

0 Answers  


if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and 1 original as it is,how?

5 Answers  






What is the use of placing primary key and foreign key constrains on columns.

4 Answers   Value Labs,


Explain Normalization and DE normalization

0 Answers   iNautix,


Why you need indexing? Where that is stored and what you mean by schema object? For what purpose we are using view?

0 Answers  


what is the difference between group and having give an example with query and sample output

7 Answers  


Define right outer join?

0 Answers  


Explain the commands in sql server?

0 Answers  


What is difference between materialized view and view?

0 Answers  


Categories