Update in cursors - TSQL Tutorial

In this page you can learn how to update rows from table using delete operation in cursors.


Update in cursors example:

USE model;
GO
DECLARE test_cursor CURSOR LOCAL FOR
   SELECT id, first_name, last_name, section
   FROM dbo.students WHERE id = 2;
OPEN test_cursor;
FETCH test_cursor;
UPDATE dbo.students
SET section = 'Medicine'
FROM dbo.students
WHERE CURRENT OF test_cursor;
GO

SELECT id, first_name, last_name, section FROM dbo.students;
GO

idfirst_namelast_namesection
2MichaelJONESMedicine