我们如何告诉SQLCMD继续“错误”下一个批次?
关于如何实现这一目标的任何想法?
USE [db_name]
BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT; //If error continue with next batch
BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT;
...
Any ideas on how to accomplish this?
USE [db_name]
BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT; //If error continue with next batch
BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT;
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在命令行上使用
-v
标志。如果您设置了足够大的价值(例如17),那么即使是相当严重的错误也不会停止脚本。例如
sqlcmd ... -v 17 -i myfile.sql
我会假设您知道执行此操作时正在做什么,并且正在监视错误消息。
您可能会更高,直至25级,但是如果您在17至25级之间遇到错误,那么您不太可能会进步,因为它们往往是由服务器上的软件或硬件错误引起的,而不是要输入的脚本中错误。
Use the
-V
flag on the command-line. If you set a sufficiently large enough value (e.g 17), even fairly severe errors will not stop the script.e.g.
sqlcmd ... -V 17 -i MyFile.sql
I will assume that you know what you're doing when you do this and are monitoring the error messages nonetheless.
You could go higher, up to level 25, but if you're getting errors between level 17 and 25, it's unlikely that you're going to be able to progress much because they tend to be caused by software or hardware errors on the server, rather than errors in the scripts you're inputting.
批处理中断错误的行为是SQL Server(即后端)选项,并由错误严重性控制。无法更改服务器行为,中断批处理的错误总是会中断批处理。
文件延续的行为(错误在错误后运行下一个划分的批次)是SQLCMD选项,由
-B
Switch控制。默认情况下是打开(含义SQLCMD在下一批中继续)。The behavior of batch interruption on error is a SQL Server (ie. backend) option and is governed by error severity. There is no way to change the server behavior, errors that interrupt the batch will always interrupt the batch, period.
The behavior of file continuation (run the next GO delimited batch after error) is a sqlcmd option and is controlled by the
-b
switch. By default is ON (meaning sqlcmd continues with the next batch).