SQLServer 查询近期执行的sql语句

2022/9/3 2:22:45

本文主要是介绍SQLServer 查询近期执行的sql语句,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

SELECT TOP 1000 
 QS.creation_time AS '执行时间' , 
   QS.total_elapsed_time/1000 AS '耗时',
    QS.total_rows,
 SUBSTRING(ST.text,qs.statement_start_offset/2+1,
        (CASE WHEN qs.statement_end_offset = -1
        THEN DATALENGTH(ST.text)
        ELSE qs.statement_end_offset END -qs.statement_start_offset)/2 + 1)
    AS [使用CPU的语法],
      -- ST.text AS '执行的SQL语句',
       QS.execution_count AS '执行次数',
     
       QS.total_logical_reads AS '逻辑读取次数',
       QS.total_logical_writes AS '逻辑写入次数',
       QS.total_physical_reads 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 '2022-07-03 19:17:15' AND '2022-09-02 17:52:15'     --and st.text like '%MERGE%'
and  SUBSTRING(ST.text,qs.statement_start_offset/2+1,
        (CASE WHEN qs.statement_end_offset = -1
        THEN DATALENGTH(ST.text)
        ELSE qs.statement_end_offset END -qs.statement_start_offset)/2 + 1) like 'update %' --sql语句
ORDER BY
     QS.creation_time DESC


这篇关于SQLServer 查询近期执行的sql语句的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程