Close cursors - TSQL Tutorial

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

IDFIRST_NAME
1Tom
2Michael
3Sophia
4Emma
5Olivia
6David