How to get SQLCMD to output errors and warnings only(如何让 SQLCMD 仅输出错误和警告)
问题描述
如何让 SQLCMD 在执行 SQL 脚本文件时仅输出遇到的任何错误或警告?
How can you get SQLCMD, when executing a SQL script file, to just output any errors or warnings it encounters?
我基本上不希望输出基于信息的消息.
I essentially dont want information based messages to be output.
推荐答案
无法通过传递参数来阻止 SQLCMD 返回非错误输出消息.
It's not possible to prevent SQLCMD returning non-error output messages by passing it a parameter.
但是,您可以将错误消息重定向到 STDERR,然后将所有其他消息重定向到 NUL.
However, what you can do is redirect error messages to STDERR, then direct all other messages to NUL.
这是通过传递 -r 参数来完成的.来自在线书籍:
This is done by passing the -r parameter. From books online:
-r[ 0 |1] 向标准错误发送消息
-r[ 0 | 1] msgs to stderr
将错误消息输出重定向到屏幕 (stderr).如果不指定参数或指定 0,则仅重定向严重级别为 11 或更高的错误消息.如果指定 1,则重定向所有错误消息输出,包括 PRINT.如果使用 -o 则无效.默认情况下,消息被发送到标准输出.
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.
根据您要显示的错误消息设置 -r,但要显示所有错误消息输出,示例命令为:
Set -r depending on exactly which error messages you want to display, but to display all error message output, an example command would be:
sqlcmd -Q "select 1 as a; select 1/0 as b" -E -r1 1> NUL
这篇关于如何让 SQLCMD 仅输出错误和警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 SQLCMD 仅输出错误和警告
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
