Start Updating tables within cursor loop

Updating tables within cursor loop

Finally, we close the cursor we opened using CLOSE keyword.

statement to request that locks be placed on all rows identified by the query.

You should do this whenever you expect to change some or all of those rows, and you don't want another session to change them out from under you.

There are 15 rows in the employee table and so this won’t illustrate the performance issues that cursors can suffer but if the table contained The above code creates two variables @Emp Id and @Emp Name that will hold the id and name from the employee table respectively.

To declare a cursor we use the DECLARE keyword followed by the cursor’s name and the FOR keyword.

To move the cursor to the first row we use the FETCH NEXT command.

We then use the INTO statement to fetch data from the cursor and insert it into our local variables.

The goal is to manipulate the data in a way that the Value column has iterative values from 1 to 50 instead of just values of 1.