Go SQL server–find Most expensive Queries Using DMV

Source: Internet
Author: User

Transferred from: http://blog.sqlauthority.com/2010/05/14/sql-server-find-most-expensive-queries-using-dmv/

The title of this post was what I can express here for this Quick blog post. I was asked in recent Query tuning consultation project, if I can share my script which I use to figure out which is the M OST expensive queries is running on SQL Server. This script was very basic and very simple, there was many different versions is available online. This basic script does does the job which I expect to do–find out of the most expensive queries on SQL Server Box.

SELECT TOP ten SUBSTRING (qt. TEXT, (QS.STATEMENT_START_OFFSET/2) +1,
(Case Qs.statement_end_offset
WHEN-1 then Datalength (qt. TEXT)
ELSE Qs.statement_end_offset
End-qs.statement_start_offset)/2) +1),
Qs.execution_count,
Qs.total_logical_reads, Qs.last_logical_reads,
Qs.total_logical_writes, Qs.last_logical_writes,
Qs.total_worker_time,
Qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_s,
qs.last_elapsed_time/1000000 last_elapsed_time_in_s,
Qs.last_execution_time,
Qp.query_plan
From Sys.dm_exec_query_stats QS
Cross APPLY sys.dm_exec_sql_text (Qs.sql_handle) QT
Cross APPLY sys.dm_exec_query_plan (qs.plan_handle) QP
ORDER by Qs.total_logical_reads DESC--logical reads
--ORDER by Qs.total_logical_writes DESC--Logical writes
--ORDER by Qs.total_worker_time DESC--CPU time

You can change the ORDER BY clause to order this table with different parameters. I invite my reader to share their scripts.

Go SQL server–find Most expensive Queries Using DMV

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.