zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    .NET:如何应对边界异常?
    由极点五笔到QQ五笔的转换想到的
    【转】七个受用一生的心理寓言
    proverb: better late than never
    背单词软件supermemo从2006版升级到2008版
    今天解决一个异步刷新TreeView的问题
    开始尝试换成Windows 7了
    southpaw
    用supermemo背单词达到6000词条
    Averse, Adverse
  • 原文地址:https://www.cnblogs.com/grj001/p/12222963.html
Copyright © 2011-2022 走看看