Cursors in SQL Server

Cursors:
Cursors are simply defined as “It’s an iterator over the collection of rows in the recordset”.
Using cursors, the client can get, put, and delete database records. Database programmers use cursors for processing individual rows returned by the database system for a query.

Syntax:
DECLARE cursor_name CURSOR FOR SELECT ... FROM...
It declares a cursor with a name for the table to be accessed.

OPEN cursor_name
Open statement places the cursor before first row in the resultset.

FETCH cursor_name INTO...
Position cursors on a specific row in the result set with the FETCH statement. A fetch operation transfers the data of the row into the application.

CLOSE cursor_name
It closes the cursor after completion of the recursive process.

0 comments:

Post a Comment

Blogger news