What is Cursor in SQL Server?
InSQL procedures, a cursor make it possible to define a result set (a set of datarows) and performs complex logic on a row by row basis. By using the samemechanics, an SQL procedure can also define a result set and return it directlyto the caller of the SQL procedure or to a client application.
Acursor can be viewed as a pointer to one row in a set of rows. The cursor canonly reference one row at a time, but can move to other rows of the result setas needed.
Touse cursors in SQL procedures, you need to do the following:
Please check this link for detailed information
- Declarea cursor that defines a result set.
- Open the cursor to establish the result set.
- Fetch the data into local variables as needed from the cursor, one row at atime.
- Close the cursor when done.