Friday, 10 June 2011

MSSQL - Finding running queries

Hi all,

I've just written this SQL for MS SQL 2005. It returns running sql queries.


select CN.session_id, ST.text, ST.dbid, ES.last_request_start_time,
ES.last_request_end_time, ES.login_name, ES.status
from sys.dm_exec_connections CN
join sys.dm_exec_sessions ES ON CN.session_id = ES.session_id
CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) as ST
where ES.status = 'running'


Trev

1 comment: