Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

How to find recent executed query in SQL Server

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


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




Viewing all articles
Browse latest Browse all 265

Trending Articles