Technical Article

SQL Server Long Query Script

,

In general, I'm going to give you a script that will give you access to the data that everyone is curious about and wants to learn. What is the longest running query in SQL Server?
Yes, the question that companies usually ask first is this question, which does not end with it. How do we correct after the birth? etc. as.
With the Query below, you can find your long running queries.
Yusuf KAHVECI
www.sqlturkiye.com
Thanks.
SELECT DISTINCT TOP 20
est.TEXT AS sqlturkiye_queryText
   ,DB_NAME(dbid)
   ,eqs.execution_count AS sqltr_execCount
   ,eqs.max_elapsed_time AS sqltr_maxelapsedTime
   ,ISNULL(eqs.total_elapsed_time / NULLIF(eqs.execution_count, 0), 0) AS sqltr_avgElapsedTime
   ,eqs.creation_time AS sqltr_CreatedTime
   ,ISNULL(eqs.execution_count / NULLIF(DATEDIFF(s, eqs.creation_time, GETDATE()), 0), 0) AS sqltr_execPerSecond
   ,total_physical_reads AS sqltr_agPhyRead
FROM sys.dm_exec_query_stats eqs
CROSS APPLY sys.dm_exec_sql_text(eqs.sql_handle) est
ORDER BY eqs.max_elapsed_time DESC

Rate

3.4 (5)

You rated this post out of 5. Change rating

Share

Share

Rate

3.4 (5)

You rated this post out of 5. Change rating