How to recover the unsaved scripts if the SSMS crashes / unsaved tab gets accidentally closed?
All you have to do is reopen SSMS and you're presented with the 'Microsoft SQL Server Management Studio Recovered Files' window. Simply clicking 'Recover Select Files' will open a temporarily saved copy of the Query window.
The default location for files and projects is the SQL Server Management Studio Projects folder in your My Documents folder.
The location of the temporary file is specified by the TMP, TMPDIR, or TEMP environment variable or by the -dt database server option. For example, dbeng16 -dt "." creates a temporary file in the current directory. The temporary file's location can be a performance consideration.
Posting this in case if somebody stumbles into same problem.
Googled for Retrieve unsaved Scripts and found a solution.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With