Friday, September 26, 2014

Recently executed query




Using below query you can get executed time and query text
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

Results of above query



Using below query you can find the Recently excuted query for specific SPID
SELECT SDEC.[most_recent_sql_handle], DEST.[text], last_read, Last_write
FROM sys.[dm_exec_connections] SDEC
 CROSS APPLY sys.[dm_exec_sql_text](SDEC.[most_recent_sql_handle]) AS DEST
WHERE SDEC.[most_recent_session_id] = 52

Results of above query

Thanks
Venkat Sangu

No comments:

Post a Comment

Cannot access the specified path or file on the server. Verify that you have the necessary security privileges and that the path or file exists

If you received below error while attaching a .mdf file in cluster environment please follow below steps to resolve the issue ERROR Ca...