Connecting with Query Editor
Applies To: SQL Server 2016
SQL Server Management Studio permits you to write or edit code while disconnected from the server. This can be useful when the server is not available or when you want to conserve scarce server or network resources. You can also change the connection of Query Editor to a new instance of SQL Server without opening a new Query Editor window or retyping your code.
On the Management Studio toolbar, click Database Engine Query to open the Query Editor.
In the Connect to Database Engine dialog box, click Cancel. The Query Editor opens, and the title bar for the Query Editor indicates that you are not connected to an instance of SQL Server.
In the code pane, type the following Transact-SQL statements:
SELECT * FROM Production.Product; GO
At this point you can connect to an instance of SQL Server by clicking Connect, Execute, Parse, or Display Estimated Execution Plan, all of which are available from either the Query menu, the Query Editor toolbar, or from the shortcut menu when you right-click in the Query Editor window. For this practice, we'll use the toolbar.
On the toolbar, click the Execute button to open the Connect to Database Engine dialog box.
In the Server name text box, type your server name, and then click Options.
On the Connection Properties tab, in the Connect to database list, browse the server to select AdventureWorks2012 and then click Connect.
To open another Query Editor window with the same connection, on the toolbar click New Query.
To change connections, right-click in the Query Editor window, point to Connection, and then click Change Connection.
In the Connect to SQL Server dialog box, select another instance of SQL Server if available, and then click Connect.
This new feature of Query Editor enables you to easily run the same code on several servers. This may be useful for maintenance actions involving similar servers.