T-SQL Tutorial

Deallocate cursors - TSQL Tutorial


When the cursor is deallocated, the data structures comprising the cursor are released by Microsoft SQL Server.

Deallocate cursor Syntax:

DEALLOCATE { { cursor_name } | cursor_variable_name }




Deallocate cursor example:

USE model;
GO
DECLARE @CursorName CURSOR
SET @CursorName = CURSOR LOCAL SCROLL FOR
SELECT * FROM dbo.students;

DEALLOCATE @CursorName;

SET @CursorName = CURSOR LOCAL SCROLL FOR
SELECT * FROM dbo.students;
GO

Output
Command(s) completed successfully.