如何让SQLCMD仅输出错误和警告

前端之家收集整理的这篇文章主要介绍了如何让SQLCMD仅输出错误和警告前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在执行sql脚本文件获取sqlCMD,只输出遇到的任何错误或警告?

我基本上不希望输出基于信息的消息.

解决方法

通过传递参数,无法阻止sqlCMD返回非错误输出消息.

但是,您可以做的是将错误消息重定向到STDERR,然后将所有其他消息定向到NUL.

这是通过传递-r参数完成的.从books online开始:

-r[ 0 | 1] msgs to stderr

Redirects the error message output to the screen (stderr). If you do not specify a parameter or if you specify 0,only error messages that have a severity level of 11 or higher are redirected. If you specify 1,all error message output including PRINT is redirected. Has no effect if you use -o. By default,messages are sent to stdout.

@H_403_17@

设置-r取决于您要显示哪些错误消息,但要显示所有错误消息输出,示例命令将是:

sqlcmd -Q "select 1 as a; select 1/0 as b" -E -r1 1> NUL
原文链接:https://www.f2er.com/mssql/76340.html

猜你在找的MsSQL相关文章