I live by the phrase, "Save early and often!” Throughout
my career I have preached it to others with the kind of fatherly tone that conveys
an attitude of “been-there” as well as “I know better”. It’s a good axiom to
remember and practice, and yesterday, I was kicking myself all over my office
because I didn’t.
I was writing code in SQL Server Management Studio (SSMS), the typical plan, write, test cycle. I spent a good part of the day working with a particuallarly nasty data set. Sometimes I would run the operations
in-whole, other-times in segments. Then, after hours of intense focus and concentration,
a colleague IM’d me a simple question. To answer her, I opened a SQL file containing the logic, typed out a quick response and closed the SQL file quickly, dismissing the warning. It was then that I realized I had closed the wrong file. Instant panic hit me as I realized a half-day of work was just thrown away, there is no auto-save in SSMS. It hit me like a ton-of-bricks that all my hard work was lost.
Luckly, Bing (I'm sure Google could have done it too) came to my rescue when I searched for an answer.
https://stackoverflow.com/questions/15034832/recover-unsaved-sql-query-scripts
https://stackoverflow.com/questions/15034832/recover-unsaved-sql-query-scripts
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
After running the query, I had to scroll through many-many results until I found the last time I had run my code completely. When copied and pasted into a new query window, I had my work back! With a little formatting (it pasted in as a single line), I was back in business and, this time, I made sure to save it right away. My grateful thanks to the microsoft techs who made this possible for me!
No comments:
Post a Comment