SQLServer 查看耗时较多的SQL语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SELECT TOP 50 total_worker_time / 1000                         AS [总消耗CPU 时间(ms)],
              execution_count                                  AS [运行次数],
              qs.total_worker_time / qs.execution_count / 1000 AS [平均消耗CPU 时间(ms)],
              last_execution_time                              AS [最后一次执行时间],
              max_worker_time / 1000                           AS [最大执行时间(ms)],
              SUBSTRING(qt.text, qs.statement_start_offset / 2 + 1,
                        (IIF(qs.statement_end_offset = -1, DATALENGTH(qt.text), qs.statement_end_offset) -
                         qs.statement_start_offset) / 2 + 1)
                                                               AS [使用CPU的语法],
              qt.text                                          AS [完整语法],
    dbname=db_name(qt.dbid),
              object_name(qt.objectid, qt.dbid)                AS ObjectName
FROM sys.dm_exec_query_stats qs WITH (nolock)
         CROSS apply sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE execution_count > 1
ORDER BY total_worker_time DESC

 

本文作者:iHey

本文链接:https://www.cnblogs.com/iHey/p/15946694.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   iHey  阅读(735)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.