Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Find Most Expensive Queries Using DMV

Posted on April 29, 2013October 26, 2015 By David Kittell
SELECT TOP 10 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

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

Originally Posted on April 29, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL - Audit

Post navigation

Previous post
Next post

Related Posts

Token String

Posted on July 8, 2014October 26, 2015

This PHP function will assist in splitting a string based on characters. $string = "This istan examplenstring"; /* Use tab and newline as tokenizing characters as well */ $tok = strtok($string, " nt"); while ($tok !== false) { echo "Word=$tok<br />"; $tok = strtok(" nt"); } $first_token = strtok(‘/something’, ‘/’);…

Read More

Regex Match

Posted on August 6, 2013October 26, 2015

IF OBJECT_ID(N’dbo.RegexMatch’) IS NOT NULL DROP FUNCTION dbo.RegexMatch GO CREATE FUNCTION dbo.RegexMatch ( @pattern VARCHAR(2000) ,@matchstring VARCHAR(MAX) –Varchar(8000) got SQL Server 2000 ) RETURNS INT /* The RegexMatch returns True or False, indicating if the regular expression matches (part of) the string. (It returns null if there is an error)….

Read More

PowerShell – Windows DNS Server Basics

Posted on May 11, 2018

# Windows Version – Helps to know what version as some things change from one version to another. (Get-WmiObject -class Win32_OperatingSystem).Caption $ZN = "kittell.net" # List DNS Forwarders – Where to go if DNS record not in this DNS server Get-DnsServerForwarder # Remove DNS Server Forwards #Remove-DnsServerForwarder -IPAddress 8.8.8.8 -PassThru…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes