What is an SQL cursor ?

SQL cursor

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 .

What is an SQL cursor ? was last modified: October 1st, 2017 by Justin Antony

How does a SQL cursor looks ?

SQL cursor example

DECLARE @MyCursor CURSOR
SELECT COL1,COL2 FROM TBL
OPEN @MyCursor
FETCH NEXT FROM @MyCursor INTO @Col1,@Col2
WHILE @@FETCH_STATUS = 0
BEGIN
----------------------------
This is the place you need to input which will gets executed based on the number of rows selected by the select statement
-----------------------------
FETCH NEXT FROM @MyCursor INTO @Col1,@Col2
END
CLOSE @MyCursor
DEALLOCATE @MyCursor
How does a SQL cursor looks ? was last modified: October 1st, 2017 by Justin Antony