SQL Server中查看哪些游标未释放

SQL SERVER提供了一个动态管理函数sys.dm_exec_cursors,返回有关在数据库中打开的游标的信息。

 

一、语法

dm_exec_cursors (session_id | 0 )


 

二、参数说明

session_id | 0:会话的 ID。

1、如果指定了 session_id,则此函数返回有关指定会话中游标的信息。

2、如果指定了 0,则此函数返回有关所有会话的所有游标的信息。

 


三、查询没有关闭的游标

需要对字段is_open进行过滤(指定游标是否处于打开状态。1为打开,0表示关闭)


SELECT  session_id ,
        cursor_id ,
        name ,
        creation_time ,
        is_open
FROM    sys.dm_exec_cursors(0)
WHERE   is_open = 1;



四、已经关闭,但是没有释放的游标

 

过滤 is_open=0

 

SELECT  session_id ,
        cursor_id ,
        name ,
        creation_time ,
        is_open
FROM    sys.dm_exec_cursors(0)
WHERE   is_open = 0;



参考资料:SQL Server中查看哪些游标未释放  http://www.studyofnet.com/news/1170.html


你可能感兴趣的:(sql,server)