查询SQL Server执行过的SQL语句(执行次数)

执行语句:

SELECT TOP 2000 
       ST.text AS '执行的SQL语句',
       QS.execution_count AS '执行次数',
       QS.total_elapsed_time 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 '2020-06-11 00:00:00' AND '2020-06-12 00:00:00' 
ORDER BY
     QS.total_elapsed_time DESC

效果图:

 

PS:使用以上语句的意义在于找到那些语句被执行的次数比较频繁,进而优化接口,然后找出那些sql语句执行时间长,进而做性能分析,加入查询索引等

posted @ 2020-06-11 11:16  代码沉思者  阅读(2439)  评论(0编辑  收藏  举报