试试stackoverflow这个回答中的方法,我这里测试是可以的
SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
WHERE dest.dbid = DB_ID('msdb')
ORDER BY deqs.last_execution_time DESC
没选择master库
SELECT TOP 1000
ST.text AS '执行的SQL语句' ,
QS.execution_count AS '执行次数' ,
QS.total_elapsed_time / 10000 AS '耗时' ,
QS.total_logical_reads AS '逻辑读取次数' ,
QS.total_logical_writes AS '逻辑写入次数' ,
QS.total_physical_reads AS '物理读取次数' ,
QS.creation_time AS '执行时间' ,
QS.*
FROM sys.dm_exec_query_stats QS
CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) ST
WHERE QS.creation_time BETWEEN '2006-11-17'
AND GETDATE()
ORDER BY creation_time DESC