When running a script in SQLCMD, is there a setting, parameter or any other way of making it effectively run a GO command at the end of each SQL statement?
This would prevent the need to insert periodic GO commands into very large scripts.
In the command line, you need to use GO because that way, you know that the T-SQL statement ended and you know that you can execute it. For example, this T-SQL query will show the databases. The query requires a GO at the end to inform to sqlcmd that it is the end of the batch.
The sqlcmd utility is a command-line utility for ad hoc, interactive execution of Transact-SQL statements and scripts and for automating Transact-SQL scripting tasks.
Hmmm, I guess this is not going to help but is an answer to your question:
http://msdn.microsoft.com/en-us/library/ms162773.aspx
-c cmd_end Specifies the batch terminator. By default, commands are terminated and sent to SQL Server by typing the word "GO" on a line by itself. When you reset the batch terminator, do not use Transact-SQL reserved keywords or characters that have special meaning to the operating system, even if they are preceded by a backslash.
Especially the last sentence sounds daunting....
If all your lines end in ; and there is no ; any where else (in text fields for example) try
sqlcmd -c ;
No.
SQLCMD would have to implement a full T-SQL parser itself in order to determine where the statement boundaries are. Whereas as it currently exists, all it has to do is find lines with "GO" on them.
Determining statement boundaries can be quite tricky, given that ";" terminators are still optional for most statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With