Closes an open cursor by releasing the current result set and freeing any cursor locks held on the rows on which the cursor is positioned. CLOSE leaves the data structures accessible for reopening, but fetches and positioned updates are not allowed until the cursor is reopened. CLOSE must be issued on an open cursor; it is not allowed on cursors that have only been declared or are already closed.
CLOSE { { [GLOBAL] cursor_name } | cursor_variable_name }
This example shows the correct placement of the CLOSE statement in a cursor based process.
USE pubs
GO
DECLARE authorcursor CURSOR FOR
SELECT au_fname, au_lname
FROM authors
ORDER BY au_fname, au_lname
OPEN authorcursor
FETCH NEXT FROM authorcursor
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM authorcursor
END
CLOSE authorcursor
DEALLOCATE authorcursor
GO
OPEN | FETCH |
DEALLOCATE | Cursors |