How to view running queries in Sql Server

To see which queries are currently executing on a server, you can use this query:

SELECT sqltext.TEXT,

req.session_id,

req.status,

req.command,

req.cpu_time,

req.total_elapsed_time /1000 as 'Elapsed time, seconds',

req.total_elapsed_time /1000 / 60 as 'Elapsed time, minutes'

FROM sys.dm_exec_requests req

CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext;

 

 

Query can be killed using this command:

kill session_id

 

Something tells me it’s not a great idea to use it, though.. need to read more on it.

Leave a Reply

Your email address will not be published. Required fields are marked *