• SQL SERVER 查看数据库执行过哪些语句(SQL历史语句记录)


    SQL SERVER 查看数据库执行过哪些语句(SQL历史语句记录)

    1、查看SQL执行效率和语句

    Select TOP 1000 
           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-07-01 00:00:00' AND '2020-09-02 11:00:00' 
    orDER BY
         QS.total_elapsed_time DESC 

    2、其他参考

    SELECT TOP 50
     (total_logical_reads + total_logical_writes) AS total_logical_io,
     (total_logical_reads / execution_count) AS avg_logical_reads,
     (total_logical_writes / execution_count) AS avg_logical_writes,
     (total_physical_reads / execution_count) AS avg_phys_reads,
    substring (st.text,
    (qs.statement_start_offset / 2) + 1,
    ((CASE qs.statement_end_offset WHEN -1
     THEN datalength (st.text)
    ELSE qs.statement_end_offset END
     - qs.statement_start_offset)/ 2)+ 1)
     AS statement_text,
    *
    FROM sys.dm_exec_query_stats AS qs
     CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) AS st
    ORDER BY total_logical_io DESC 
    

      

    创建时间:2020.07.17  更新时间:

  • 相关阅读:
    Entity Framework Code First 学习日记(1)精
    敏捷宣言
    VS2013中web项目中自动生成的ASP.NET Identity代码思考
    ReSharper 配置及用法
    MVC中的Repository模式
    关于Repository模式
    Entity Framework 学习总结之十一:POCO
    Linux Centos7 离线安装docker 【官网翻译和注释】
    企业服务总线ESB
    面向服务的架构SOA
  • 原文地址:https://www.cnblogs.com/guorongtao/p/13329744.html
Copyright © 2020-2023  润新知