This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one SQL Script to find TOP 20 most used or executed query in SQL Server.
Database Administrator always prefers to find most long running queries, but It is also required to check most executed queries.
Because most executed queries might take average 1 second or 2 second for execution, but total number execution count 10 times than few long running queries.
If we find the total number of execution count more than our expectation, we can take the necessary decision like: remove redundant queries from the code.
SELECT TOP 20
deqs.execution_count AS TotalExecutionTime
,OBJECT_NAME(objectid) AS ObjectName
,QueryText = SUBSTRING(
(CASE WHEN deqs.statement_end_offset = -1
THEN len(CONVERT(nvarchar(MAX), dest.text)) * 2
END - deqs.statement_start_offset)/2)
,DatabaseName = db_name(dest.dbid)
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.execution_count DESC
You can also access few related articles: