Last executed queries on SQL Server
I have tried this code snippet to get last n queries from SQL SERVER:
SELECT deqs.last_execution_time AS [Time],
dest.TEXT AS [Query]
FROM
sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY
deqs.last_execution_time DESC
But as per documentations also, I am understanding is that sys.dm_exec_query_stats returns aggregated results, so if a query is ran for three times(simultaneously or may be with a minute time difference) it will show as one query.
So is there a way by which I can see precisely how many times a query is getting executed on server.
May be my understandings are not quite clear wrt sys.dm_exec_query_stats but please help if this query is correct or if there is another way to have the required result.
I have tried this code snippet to get last n queries from SQL SERVER:SELECT deqs.last_execution_time AS [Time],
dest.TEXT AS [Query]
FROM
sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY
deqs.last_execution_time DESCBut as per documentations also, I am understanding is that sys.dm_exec_query_stats returns aggregated results, so if a query is ran for three times(simultaneously or may be with a minute time difference) it will show as one query. So is there a way by which I can see precisely how many times a query is getting executed on server.May be my understandings are not quite clear wrt sys.dm_exec_query_stats but please help if this query is correct or if there is another way to have the required result. Read More