0Day Forums
Recover unsaved SQL query scripts - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Database (https://0day.red/Forum-Database)
+---- Forum: Microsoft SQL Server (https://0day.red/Forum-Microsoft-SQL-Server)
+---- Thread: Recover unsaved SQL query scripts (/Thread-Recover-unsaved-SQL-query-scripts)

Pages: 1 2


Recover unsaved SQL query scripts - aarikacitxfei - 07-31-2023

How to recover the unsaved scripts if the SSMS crashes / unsaved tab gets accidentally closed?


RE: Recover unsaved SQL query scripts - jacki769 - 07-31-2023

Posting this in case if somebody stumbles into same problem.

Googled for [Retrieve unsaved Scripts][1] and found a solution.


[1]:

[To see links please register here]




Run the following **`select`** script. It provides a list of scripts and its time of execution in the last 24 hours. This will be helpful to retrieve the scripts, if we close our query window in SQL Server management studio without saving the script. It works for all executed scripts not only a view or procedure.

Use <database>
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC


RE: Recover unsaved SQL query scripts - malformation745 - 07-31-2023

You can find files here, when you closed SSMS window accidentally

C:\Windows\System32\SQL Server Management Studio\Backup Files\Solution1



RE: Recover unsaved SQL query scripts - underneath377 - 07-31-2023

I am using Windows 8 and found the missing scripts in the path below:

C:\Users\YourUsername\Documents\SQL Server Management Studio\Backup Files


RE: Recover unsaved SQL query scripts - barnesbxdjaamo - 07-31-2023

SSMSBoost add-in (currently free)

- keeps track on all executed statements (saves them do disk)
- regulary saves snapshot of SQL Editor contents. You keep history of the modifications of your script. Sometimes "the best" version is not the last and you want to restore the intermediate state.
- keeps track of opened tabs and allows to restore them after restart. Unsaved tabs are also restored.

+tons of other features.
(I am the developer of the add-in)


RE: Recover unsaved SQL query scripts - arleenad - 07-31-2023

Go to SSMS >> Tools >> Options >> Environment >> AutoRecover

There are two different settings:

1) Save AutoRecover Information Every Minutes

This option will save the SQL Query file at certain interval. Set this option to minimum value possible to avoid loss. If you have set this value to 5, in the worst possible case, you can lose last 5 minutes of the work.

2) Keep AutoRecover Information for Days

This option will preserve the AutoRecovery information for specified days. Though, I suggest in case of accident open SQL Server Management Studio right away and recover your file. Do not procrastinate this important task for future dates.


RE: Recover unsaved SQL query scripts - erzsebetxiqokdtp - 07-31-2023

I was able to recover my files from the following location:


C:\Users\<yourusername>\Documents\SQL Server Management Studio\Backup Files\Solution1

There should be different recovery files per tab. I'd say look for the files for the date you lost them.


RE: Recover unsaved SQL query scripts - Mromarlbaskll - 07-31-2023

Use the following location where you can find all `~AutoRecover.~vs*.sql` (*autorecovery files*):

C:\Users\<YourUserName>\Documents\SQL Server Management Studio\Backup Files\Solution1


RE: Recover unsaved SQL query scripts - freshwater871 - 07-31-2023

You *may* be able to find them in one of these locations (depending on the version of Windows you are using).

Windows XP

C:\Documents and Settings\YourUsername\My Documents\SQL Server Management Studio\Backup Files\

Windows Vista/7/10

%USERPROFILE%\Documents\SQL Server Management Studio\Backup Files

OR

%USERPROFILE%\AppData\Local\Temp


[Googled from this source][1] and [this source.][2]


[1]:

[To see links please register here]

[2]:

[To see links please register here]




RE: Recover unsaved SQL query scripts - anoplothere486259 - 07-31-2023

For SSMS 18, I found the files at:

C:\Users\YourUserName\Documents\Visual Studio 2017\Backup Files\Solution1


For SSMS 17, It was used to be at:

C:\Users\YourUserName\Documents\Visual Studio 2015\Backup Files\Solution1