Appear in Online Interview to test your skills and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Submit content and win cash & prizes monthly.
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Articles Author
Fri, 25-Apr-2014 Authors
All Time Authors
Rajkatie
20480
Vishal@Neeraj
19600
Bharathi Cherukuri
18040

Latest members | More ...


(Statistics delayed by 5 minutes)

What is cursor in SQL Server?

 Posted by Raja on 12/14/2008 | Category: Sql Server Interview questions | Views: 97256
Answer:

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.

Typical syntax of cursor is

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


To know more about cursor, see
http://www.mssqlcity.com/Articles/General/UseCursor.htm


Asked In: Many Interviews | Alert Moderator 

Found interesting? Add this to:




Comments or Responses

Posted by: Alok on: 1/18/2013 | Points: 10

can we call cursor from front end

Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.