So far in this series we've been concerned with simply reading data from tables using a cursor.
In this final part we'll look at how you can use a cursor to modify data as well.
UPDATE [OF must conform to the rules for identifiers.
LOCAL Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created. The cursor can be referenced by local cursor variables in the batch, stored procedure, or trigger, or a stored procedure OUTPUT parameter.
The cursor name can be referenced in any stored procedure or batch executed by the connection.
GLOBAL Specifies that the scope of the cursor is global to the connection.
To make sure the correct values are added to the correct records we use the WHERE CURRENT OF statement to check the current position of our cursor.
When you use a Transact-SQL server cursor, you can update the current row by using an UPDATE statement that includes a WHERE CURRENT OF clause.
The cursor cannot be referenced in a WHERE CURRENT OF clause in an UPDATE or DELETE statement.
This option overrides the default capability of a cursor to be updated.