sql – get running queries

Use the following snippet to get running queries on an Microsoft SQL Server.

SELECT 
	sqltext.TEXT,
	req.user_id,
	req.session_id,
	req.status,
	req.command,
	req.cpu_time,
	req.total_elapsed_time,
	total_min = req.total_elapsed_time/1000/60,
	total_hours = req.total_elapsed_time/1000/60/60
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

To stop a running query, take the session_id and write KILL 12 if 12 corresponds to the session_id

Leave a Reply

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