查看SQLServer最耗资源时间的SQL语句
作者:互联网
1 SELECT (total_elapsed_time / execution_count) / 1000 N'平均时间ms' 2 , total_elapsed_time / 1000 N'总花费时间ms' 3 , total_worker_time / 1000 N'所用的CPU总时间ms' 4 , total_physical_reads N'物理读取总次数' 5 , total_logical_reads / execution_count N'每次逻辑读次数' 6 , total_logical_reads N'逻辑读取总次数' 7 , total_logical_writes N'逻辑写入总次数' 8 , execution_count N'执行次数' 9 , SUBSTRING(st.text, (qs.statement_start_offset / 2) + 1 10 , ((CASE statement_end_offset 11 WHEN -1 THEN DATALENGTH(st.text) 12 ELSE qs.statement_end_offset END 13 - qs.statement_start_offset) / 2) + 1) N'执行语句' 14 , creation_time N'语句编译时间' 15 , last_execution_time N'上次执行时间' 16 FROM sys.dm_exec_query_stats AS qs 17 CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st 18 WHERE SUBSTRING(st.text, (qs.statement_start_offset / 2) + 1, 19 ((CASE statement_end_offset 20 WHEN -1 THEN DATALENGTH(st.text) 21 ELSE qs.statement_end_offset END 22 - qs.statement_start_offset) / 2) + 1) not like 'fetch%' 23 ORDER BY total_elapsed_time / execution_count DESC;
标签:qs,time,text,offset,SQLServer,最耗,statement,SQL,total 来源: https://www.cnblogs.com/iHey/p/16290959.html