The primary way to recover unsaved queries is through the built-in feature.
Losing a complex SQL script due to a sudden crash or accidental tab closure is a frustrating experience for any database professional. Fortunately, SQL Server Management Studio (SSMS) includes several built-in mechanisms and hidden system caches that can help you recover unsaved work. 1. Using SSMS Auto-Recovery sql management studio recover unsaved query