我有一堆运行存储过程的exec命令,其中25个是准确的。
exec stp_1
exec stp_2
exec stp_3
依旧......
有没有办法知道哪个exec命令正在执行?在查询窗口中,我只看到"执行查询"。我运行sp_who
但是无法告诉哪个执行官正在执行。
答案 0 :(得分:1)
试试这个
SELECT r.start_time [Start Time],session_ID [SPID],
DB_NAME(database_id) [Database],
SUBSTRING(t.text,(r.statement_start_offset/2)+1,
CASE WHEN statement_end_offset=-1 OR statement_end_offset=0
THEN (DATALENGTH(t.Text)-r.statement_start_offset/2)+1
ELSE (r.statement_end_offset-r.statement_start_offset)/2+1
END) [Executing SQL],
Status,command,wait_type,wait_time,wait_resource,
last_wait_type
FROM sys.dm_exec_requests r
OUTER APPLY sys.dm_exec_sql_text(sql_handle) t
WHERE session_id != @@SPID
AND session_id > 50 -- don't show system queries
ORDER BY r.start_time
答案 1 :(得分:0)
试试这个:
SELECT
DMExQryStats.last_execution_time AS [Executed At],
DMExSQLTxt.text AS [Query]
FROM
sys.dm_exec_query_stats AS DMExQryStats
CROSS APPLY
sys.dm_exec_sql_text(DMExQryStats.sql_handle) AS DMExSQLTxt
ORDER BY
DMExQryStats.last_execution_time DESC