Skip to main content


Showing posts from September, 2017

How to find recent executed query in SQL Server

Sometimes we do R&D on the query and try to found the solution of any problem and due to some reason you shut down your system without saving the query and next you need to recover your R&D query, so using the following query you can recover your executed query.

sys.dm_exec_query_stats and sys.dm_exec_sql_text catalog the view records for all currently executed query using the following query we can find the recently executed query.

SELECTdest.TEXTAS[MyQuery],a.last_execution_timeAS[DateTime] FROMsys.dm_exec_query_statsASa CROSSAPPLYsys.dm_exec_sql_text(a.sql_handle)ASdest WHEREa.last_execution_time>dateadd(day,-1,