Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Fri, 31-Oct-2014 Authors
All Time Authors
Vishal@Neeraj
38680
Rajkatie
20600
Bharathi Cherukuri
18040

Latest members | More ...


(Statistics delayed by 5 minutes)
 Interview Question

What is cursor in SQL Server?

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

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