Friday, May 9, 2014

How to recover unsaved queries from SQL Server Management Studio

How to recover unsaved queries from SQL Server Management Studio

We developed a script and suddently SSMS crashed and we lost our script, how can we recover that unsaved query

Method  - 1
Try on the following locations on Windows 7
C:\Users\\Documents\SQL Server Management Studio\Backup Files\Solution1
(OR)
C:\Users\AppData\Local\Temp  -- Search for *.sql files and try your luck.

Method - 2   -- Use the below query and try to recover the query

Select t.text, q.last_execution_time from sys.dm_exec_query_stats as q
cross apply sys.dm_exec_sql_text(q.sql_handle) as t
order by q.last_execution_time desc

Note : This will not work always but you can try your luck.

No comments: