Today I am posting a pretty useful query which is mostly required during the Optimization phase of the project.
Following query will return information about how much time each individual query within your stored procedures of a
specific database is taking and will help in analysis purpose.
Just run the below query on your database,
qs.total_elapsed_time / qs.execution_count / 1000000.0 AS average_seconds,
qs.total_elapsed_time / 1000000.0 AS total_seconds,
(CASE WHEN qs.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE qs.statement_end_offset END – qs.statement_start_offset)/2) AS individual_query,
o.name AS object_name,
DB_NAME(qt.dbid) AS database_name
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
LEFT OUTER JOIN sys.objects o ON qt.objectid = o.object_id
qt.dbid = DB_ID()
I would like to have feedback from my blog readers.
Please post your feedback, question, or comments about this article.