How to view statements with low execution efficiency in SQL Server

Source: Internet
Author: User

sql server中,如果想知道有哪些语句是执行效率不高的,应该如何查看呢?下面就将为您介绍sql server中如何查看执行效率不高的语句,供您参考。 在测量功能时,先以下命令清除sql server的缓存 dbcc freeProcCache 在点击某个按钮,执行完后,再执行下面语句,就可以知道系统运行什么Sql和多少次了,其主要慢语句是那些了; SELECT creation_time  N ‘语句编译时间‘          ,last_execution_time  N ‘上次执行时间‘          ,total_physical_reads N ‘物理读取总次数‘          ,total_logical_reads/execution_count N ‘每次逻辑读次数‘          ,total_logical_reads  N ‘逻辑读取总次数‘          ,total_logical_writes N ‘逻辑写入总次数‘          ,execution_count  N ‘执行次数‘          ,total_worker_time/1000 N ‘所用的CPU总时间ms‘          ,total_elapsed_time/1000  N ‘总花费时间ms‘          ,(total_elapsed_time / execution_count)/1000  N ‘平均时间ms‘          ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,           ((CASE statement_end_offset            WHEN -1 THEN DATALENGTH(st.text)            ELSE qs.statement_end_offset END              - qs.statement_start_offset)/2) + 1) N ‘执行语句‘ FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st where SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,           ((CASE statement_end_offset            WHEN -1 THEN DATALENGTH(st.text)            ELSE qs.statement_end_offset END              - qs.statement_start_offset)/2) + 1) not like ‘%fetch%‘ ORDER BY  total_elapsed_time / execution_count DESC;

How to view statements with low execution efficiency in SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.