Is there something like a directive which I can use in a script to force SSMS to enable/disable SQLCMD mode?
Sql-server – enable SQLCMD mode from inside a script
sql serversqlcmd
Related Question
- Sql-server – Are there any reasons not enable SQLCMD-mode as default in SSMS
- T-sql – SQLCMD mode: environment variable syntax
- Sql-server – How to get SSMS to use the relative path of the current script with :r in sqlcmd mode like SSDT does
- Sql-server – Disabling variable substitution inside SQLCMD script when using :r syntax
- Sql-server – Run aspnet_regsql.exe from SQLCMD Post-Deployment Script
- Sql-server – Variable inside another variable in SQLCMD mode
- T-sql – Messages in SQLCMD script output are not in order
- Sql-server – SQLCMD :connect directive – how can I specify connection protocol
Best Answer
As has been said, there isn't a way.
However, one thing we do is to include a quick check in our script header, to determine whether SQLCMD mode is on (and terminate the script if not):
There is a reason Severity 20 is used, it tends to kill the connection immediately, preventing any more script code from running, even if there are
GO
batch terminators later in the script.