When you open a new query window in SSMS, it creates a temporary file with a .sql extension in the C:\Users\<username>\AppData\Local\Microsoft\SQL Server Management Studio\<version>\QueryStore directory. This file contains your unsaved query. When you close the query window without saving the file, the temporary file remains on your system.
SQL Management Studio (SSMS) is a powerful tool for managing and querying Microsoft SQL Server databases. However, sometimes you may accidentally close a query window or encounter an unexpected error, causing you to lose unsaved work. Fortunately, SSMS provides a feature to recover unsaved queries. In this article, we'll walk you through the steps to recover unsaved queries in SSMS. sql management studio recover unsaved query