由于在公司服务器上在某个时段查询某个sql执行比较慢,由来查询当前正在被执行的sql
Select t.text,SUBSTRING(t.text, (r.statement_start_offset/2) + 1,
((CASE statement_end_offset WHEN -1 THEN DATALENGTH(t.text)
ELSE r.statement_end_offset END-r.statement_start_offset)/2)+1) AS stext,
r.session_id,p.Blocked,p.ios,s.login_time,s.host_name,s.program_name,s.login_name,
s.last_request_start_time
From sys.dm_exec_requests r Cross Apply (Select * From sys.dm_exec_sql_text(r.sql_handle)) t
Join Sys.dm_exec_sessions s on r.session_id=s.session_id
JOIN (Select spid,sum(physical_io) as IOS,Max(blocked) as Blocked From master.dbo.sysprocesses Group By SPID) P ON r.session_id=p.spid
Where r.session_id<>@@SPID
时间: 2024-10-07 22:59:39