Can you make SQLCMD immediately run each statement in a script without the use of “GO”?

为君一笑 提交于 2019-12-07 06:21:39

问题


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.


回答1:


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.




回答2:


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 ;


来源:https://stackoverflow.com/questions/4944165/can-you-make-sqlcmd-immediately-run-each-statement-in-a-script-without-the-use-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!