Thursday, 5 June 2014

How to Find Currently Running Query in SQL Server and Killing the session

The below query returns currently running query in SQL Server

Session Query

SELECT sqltext.TEXT,
req.session_id,
req.status,
req.command,
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
where DB_NAME(req.database_id) = 'northwind'






Kill the session

KILL [session_id] (get the session id from the above query)

Example

Kill 82