How to get previous queries executed in SQL server

Pallav Kumar
15-04-2020 17:44:17
5.00 (1 votes)
Rate:

Most of the time, we forgot about which queries we have executed or after which queries database get some specific values. Also after some queries if our database facing weird issues, in that case we also need to check log. In those cases, you should consider about how to get previous executed queries. See below code and execute in SQL server, it will get you all previous executed queries:

--Get All Previous Query Run on your SQL Server
SELECT DISTINCT TOP 100 PERCENT
t.TEXT QueryName,
s.execution_count AS ExecutionCount,
s.creation_time AS LogCreatedOn
FROM sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t
ORDER BY
s.creation_time DESC
GO

Happy Coding yes


SQL Server,



Sr. Software Engg. (India)
pallav.kumar837@gmail.com
8010265036








Search