Cursor In SQL Server

Declare Cursor

Syntax
DECLARE <Cursor name> CURSOR FOR <SELECT>
Example
DECLARE CurDepartment CURSOR FOR SELECT * FROM Department;

OPEN Cursor

Syntax
OPEN <Cursor name>
Example
OPEN CurDepartment

Close Cursor

Syntax
CLOSE <Cursor name>
Example
CLOSE CurDepartment

Free Cursor

Syntax
DEALLOCATE <Cursor name>
Example
DEALLOCATE CurDepartment

Fetch Cursor

Syntax
FETCH NEXT FROM <Cursor name> INTO <Variables>
Example
FETCH NEXT FROM CurDepartment INTO @id, @name