In this page you can learn how to close an cursor by reading the syntax and the example.
Close cursor Syntax:
CLOSE { { cursor_name } | cursor_variable_name }
Close cursor example:
USE model;
GO
DECLARE Student_Cursor CURSOR FOR
SELECT ID, FIRST_NAME FROM dbo.students;
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 |
---|---|
1 | Tom |
2 | Michael |
3 | Sophia |
4 | Emma |
5 | Olivia |
6 | David |