Advertisement
Pandaaaa906

SQL Server慢查询

May 5th, 2023
1,207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.00 KB | None | 0 0
  1. SELECT
  2.     total_physical_reads  * 8 / 1024 "总物理读(Mb)",
  3.     total_logical_reads * 8 / 1024 "总逻辑读(Mb)",
  4.     total_logical_writes * 8 / 1024 "总逻辑写(Mb)",
  5.     total_worker_time /1000/1000 "总CPU耗时(s)",
  6.     creation_time 初次执行时间,
  7.     last_execution_time 上次执行时间,
  8.     execution_count 总运行次数,
  9.     execution_count / (DATEDIFF(day, creation_time, last_execution_time) + 1) 平均每天运行次数,
  10.     total_logical_writes / execution_count * 8 "平均逻辑写(Kb)",
  11.     total_elapsed_time /1000/1000 "总用时(s)",
  12.     total_elapsed_time / execution_count /1000/1000 "平均耗时(s)",
  13.     SUBSTRING (
  14.         st.text,
  15.         ( qs.statement_start_offset/ 2 ) + 1,
  16.     ( ( CASE statement_end_offset WHEN - 1 THEN DATALENGTH( st.text ) ELSE qs.statement_end_offset END - qs.statement_start_offset ) / 2 ) + 1
  17.     ) AS statement_text
  18. FROM
  19.     sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text ( qs.sql_handle ) st
  20. ORDER BY
  21. -- total_elapsed_time desc,
  22.     total_elapsed_time / execution_count DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement