Lost SQL? Retrieve your lost SQL Script

Retrieve your lost SQL Script

Just closed down your query window and clicked No to saving any changes? No sign of the query in the Backup Files folder? Lost all your work?

Fear not! There is a solution (as log as you have executed your query at some point recently).

You can retrieve your lost SQL Script using the following query:

  execquery.last_execution_time AS [Date Time], 
  execsql.text AS [Script] 
  sys.dm_exec_query_stats AS execquery
  CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
  -- Enter anything from your script to narrow down the results:
  execsql.text like '%%'
  execquery.last_execution_time DESC

Further info can be found from this link: http://stackoverflow.com/questions/15034832/recover-unsaved-sql-query-scripts-sql-server

Leave a Reply

%d bloggers like this: