What is a cursor in SQL Server 2000 and their types?

Answer Posted / vasanthi

When will be use cursor need to perform following steps:-

1. DECLARE CURSOR

2. OPEN

3. FETCH

4. @@FETCH_STATUS

5. CLOSE

6. DEALLOCATE


1.DECLARE cursor_name CURSOR FOR SELECT_statement;

2.OPEN cursor_name;

3.FETCH cursor_name INTO variable list;

5.CLOSE cursor_name;

5.DEALLOCATE cursor_name;


sample
******

DECLARE Employee_Cursor CURSOR FOR
SELECT LastName, FirstName
FROM AdventureWorks2008R2.HumanResources.vEmployee
WHERE LastName like 'B%';

OPEN Employee_Cursor;

FETCH NEXT FROM Employee_Cursor;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Employee_Cursor
END;

CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a partition function in sql server?

537


How do you troubleshoot errors in a SQL Server Agent Job?

562


Explain system rowset functions?

558


How to select true false based on column value in sql server?

508


How to set database to be single_user in ms sql server?

569






Explain encryption of entire databases without the need for application changes in sql server 2008?

566


How can you hide the sql server instances?

519


What are the disadvantages of using querystrings to send data from one page to another?

588


How to link tables in sql server?

477


What is data modeling and Reterminal integrity?

1494


What is the stuff?

529


How to delete an existing row with delete statements in ms sql server?

556


can an order by clause be used in a creation of a view?

697


What is resource governor?

549


What is an index. What are the types?

587