SQL query windows saves all the tabs in numerical sequence after you close each window. SO for example if you are typing query in window 1 and close it and open a new query windows it labels the new windows as SQL Query2 and so on.

Does anyone know what is the purpose of saving the SQLQuery windows like this? And how to retrieve all the windows.

Retrieve meaning I was trying to view all the SQL windows or any one of the windows. So for example if I want to bring back SQL Query3, how to do it? Since each time a query windows is closed it disappear isn't it?

I have an option to save the query window each time I close it but what if I didn't?

There are tools out there (e.g. RedGate's SQL Prompt -> advert intented ) that'll allow you to save, search, and recover tabs in SSMS. Maybe one day MS will figure out that this is a very useful Add-On and decide to include it...

There are tools out there (e.g. RedGate's SQL Prompt -> advert intented ) that'll allow you to save, search, and recover tabs in SSMS. Maybe one day MS will figure out that this is a very useful Add-On and decide to include it...

Okay, there is no NATIVE way to recover the contents of a tab deliberately closed without saving the contents of the tab first.

Lynn Pettis (5/3/2014)If, while closing a tab, you do not save the sql code contained in the tab it is lost. There is no reopening a previous tab to retrieve what ever query (or queries) were in that tab.

In addition to Red Gate's tool, and if you get that, really, what else do you need, Mladen Prajdic's SSMS Toolpack also has the ability to recover tabs. Plus, it has versions of queries stored so you can see changes you've made over time to a particular query window.

As mentioned, there's no native way to do this. There are a number of products, including those from my employer, Red Gate, that can help.

These tabs are like files in notepad or Word. If you don't save them, they're gone. I typically save them quickly when I think I might use the code. I also sometimes drop a bunch of code in one large query1.sql file, commenting bits out, but keeping a scratchpad.