Shortcut: Set SQLCMD mode for all new query windows in SSMS

SQLCMD mode changes how queries are executed in SQL Server Management Studio (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.
Here’s an example of running a query against 3 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.
2018-11-15