SSMS Tips and Tricks 4-9: Setting SQLCMD mode for all new query windows

SQLCMD mode changes how queries are executed in SSMS. When using this mode, you can work with options that aren’t normally part of SQL Server T-SQL scripts.
Some installation scripts also require SQLCMD mode and will fail if it’s not enabled.
Let’s look at an example executing a query against 2 servers within the same script.
First, we open a new query window, then on the Query menu, we choose SQLCMD Mode.
Then I execute the following query:
Note the :CONNECT command is used to connect to another server.
Because everything else works pretty much the same, and you get a whole lot of additional options, you might choose to open all your new queries in SQLCMD mode. That’s easy to do.
In Tools, Options, Query Execution, SQL Server, then General, there is a checkbox to enable this.
2025-08-15