Cursor statuses

Here are the queries that findout the cursors based on their statuses

1 Find out the cursors that are allocated but not opened or closed

--Method 1


select
name from sys.dm_exec_cursors(0) where is_open =0

--Method 2

select
        cur
.cursor_name
from 
       
sys.syscursorrefs as ref inner join sys.syscursors as cur on ref.cursor_handl=cur.cursor_handle
where
       
cur.open_status =0

2 Find out the cursors that are opened and not closed

--Method 1

select
name from sys.dm_exec_cursors(0) where is_open =1

--Method 2

select
        cur
.cursor_name
from 
       
sys.syscursorrefs as ref inner join sys.syscursors as cur on ref.cursor_handl=cur.cursor_handle
where
       
cur.open_status =1

3 Find out the cursors that are allocated but not deallocated

--Method 1

select name from sys.dm_exec_cursors(0)

--Method 2

select
        cur
.cursor_name
from 
       
sys.syscursorrefs as ref inner join sys.syscursors as cur on ref.cursor_handl=cur.cursor_handle

Published 08 September 2009 15:50 by Madhivanan
Filed under: , ,

Comments

# Cursor statuses - Madhivanan

08 September 2009 22:12 by SqlServerKudos

Kudos for a great Sql Server article - Trackback from SqlServerKudos