In this page you can learn how to open an cursor by reading the syntax and the example.
Open cursor Syntax:
OPEN { { cursor_name } | cursor_variable_name }
Open cursor example:
USE model;
GO
DECLARE Student_Cursor CURSOR FOR
SELECT id, first_name, last_name, country
FROM dbo.students WHERE country != 'US';
OPEN Student_Cursor;
FETCH NEXT FROM Student_Cursor;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Student_Cursor;
END;
CLOSE Student_Cursor;
DEALLOCATE Student_Cursor;
GO
id | first_name | last_name | country |
---|---|---|---|
3 | Sophia | DAVIS | France |
4 | Emma | EVANS | Germany |
6 | David | BROWN | England |