首页 > 代码库 > 查看当前正在被执行的sql
查看当前正在被执行的sql
由于在公司服务器上在某个时段查询某个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
查看当前正在被执行的sql