• SQL SERVER 占用资源高的SQL语句


    SQL SERVER 占用资源高的SQL语句
    原创曹振华 最后发布于2019-12-03 19:45:05 阅读数 16  收藏
    展开
    --SQL SERVER 占用资源高的SQL语句:
    --查询占用cpu高的前 50 个 SQL 语句
    SELECT total_cpu_time,[total_physical_Reads], total_execution_count, number_of_statements, s2.text
          --(SELECT SUBSTRING(s2.text, statement_start_offset / 2, ((CASE WHEN statement_end_offset = -1 THEN (LEN(CONVERT(NVARCHAR(MAX), s2.text)) * 2) ELSE statement_end_offset END) - statement_start_offset) / 2) ) AS query_text
    FROM 
          (SELECT TOP 50 
                SUM(qs.total_worker_time) AS total_cpu_time, 
                SUM(total_physical_reads) AS [total_physical_Reads], 
                SUM(qs.execution_count) AS total_execution_count,
                COUNT(*) AS  number_of_statements, 
                qs.sql_handle --,
                --MIN(statement_start_offset) AS statement_start_offset, 
                --MAX(statement_end_offset) AS statement_end_offset
          FROM 
                sys.dm_exec_query_stats AS qs
          GROUP BY qs.sql_handle
          ORDER BY SUM(qs.total_worker_time) DESC) AS stats
          CROSS APPLY sys.dm_exec_sql_text(stats.sql_handle) AS s2
    --------------------------------------------------------------------
     
    --查询物理IO高的前 50 个 SQL 语句
    SELECT total_cpu_time, total_physical_Reads , total_execution_count, number_of_statements, s2.text
          --(SELECT SUBSTRING(s2.text, statement_start_offset / 2, ((CASE WHEN statement_end_offset = -1 THEN (LEN(CONVERT(NVARCHAR(MAX), s2.text)) * 2) ELSE statement_end_offset END) - statement_start_offset) / 2) ) AS query_text
    FROM 
          (SELECT TOP 50 
                SUM(qs.total_worker_time) AS total_cpu_time, 
                SUM(total_physical_reads) AS [total_physical_Reads], 
                SUM(qs.execution_count) AS total_execution_count,
                COUNT(*) AS  number_of_statements, 
                qs.sql_handle --,
                --MIN(statement_start_offset) AS statement_start_offset, 
                --MAX(statement_end_offset) AS statement_end_offset
          FROM 
                sys.dm_exec_query_stats AS qs
          GROUP BY qs.sql_handle
          ORDER BY SUM(qs.total_physical_Reads) DESC) AS stats
          CROSS APPLY sys.dm_exec_sql_text(stats.sql_handle) AS s2
    --------------------------------------------------------------------
     
    --查看实时数据库占用资源
    SELECT st.text, qp.query_plan, rq.* 
    FROM sys.dm_exec_requests RQ CROSS APPLY sys.dm_exec_sql_text(rq.sql_handle) as st 
    CROSS APPLY sys.dm_exec_query_plan(rq.plan_handle) as qp order by RQ.CPU_time desc
     
    ————————————————
    版权声明:本文为CSDN博主「曹振华」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/chadcao/article/details/103375316

  • 相关阅读:
    《PHP程序员面试笔试宝典》——如何回答非技术性问题?
    《PHP程序员面试笔试宝典》——如何回答技术性的问题?
    《PHP程序员面试笔试宝典》——如何巧妙地回答面试官的问题?
    我的新书——《PHP程序员面试笔试宝典》
    小程序"errcode":41002错误问题如何解决?
    Apache虚拟主机的搭建及相关问题解决
    PHP面试题详解
    Mysql的基本操作知识
    图片压缩
    JS点击复制
  • 原文地址:https://www.cnblogs.com/grj001/p/12222963.html
Copyright © 2020-2023  润新知