SQL 服务器异常消息格式
SQL Server Exception Message Format
在此页面 Sql Server Errors 1-999 上有一个 SQL 服务器错误列表和相关的消息文本。
例如:
Err 2627: Violation of %ls constraint '%.*ls'. Cannot insert duplicate
key in object '%.*ls'.
此异常的示例是:
Violation of UNIQUE KEY constraint
'AK_AdvanceShipmentNotices_CustomerId_PurchaseOrderNumber'. Cannot
insert duplicate key in object 'dbo.AdvanceShipmentNotices'. The
duplicate key value is (4, 1000).
示例错误文本包含占位符:%ls 和 %.*ls。查看其余的错误示例,还有许多其他占位符,例如%d、%s、%S_DATE、%hs、%S_TS、%x 等等。
问题:这些占位符是在任何地方定义的,还是我只需要自己弄清楚它们的含义?
其他示例错误:
错误 21:警告:发生在 %S_DATE 的致命错误 %d。请记下错误和时间,并联系您的系统管理员。
错误 103:以 '%.*ls' 开头的 %S_MSG 太长。最大长度为 %d。
错误 262:数据库“%.*ls”中的 %ls 权限被拒绝。
Err 407: 内部错误。文件 %hs 中的字符串例程,行 %d 失败,HRESULT 0x%x。
错误 408:在 ORDER BY 列表中遇到常量表达式,位置 %i。
错误 479:table“%.*ls”的 TABLESAMPLE 子句中的 ROWS 值或 REPEATABLE 种子“%I64d”无效。值或种子必须大于 0。
错误 532:时间戳(更改为 %S_TS)显示该行已被另一用户更新。
错误 552:CryptoAPI 函数“%ls”失败。错误 0x%x: %ls
错误 2627:违反 %ls 约束“%.*ls”。无法在对象“%.*ls”中插入重复键。
T-SQL RAISERROR
函数的文档提供了更多信息:
msg_str is a string of characters with optional embedded conversion specifications. Each conversion specification defines how a value in the argument list is formatted and placed into a field at the location of the conversion specification in msg_str. Conversion specifications have this format:
% [[flag] [width] [. precision] [{h | l}]] type
标志
Is a code that determines the spacing and justification of the substituted value.
代码:
-
: 在给定的字段宽度内左对齐参数值。
+
:如果值是有符号类型,则在参数值前面加上加号 (+) 或减号 (-)。
0
:在输出前加上零,直到达到最小宽度。当出现 0 和减号 (-) 时,忽略 0。
#
:当与 o、x 或 X 格式一起使用时,井号 (#) 标志分别在任何非零值前面加上 0、0x 或 0X。当 d、i 或 u 以数字符号 (#) 标志开头时,该标志将被忽略。
</code>(空白):如果值是有符号且为正的,则在输出值前加上空格。当包含在加号 (+) 标志中时,它会被忽略。</li>
</ul>
<p><em>宽度</em></p>
<blockquote>
<p>Is an integer that defines the minimum width for the field into which the argument value is placed. If the length of the argument value is equal to or longer than width, the value is printed with no padding. If the value is shorter than width, the value is padded to the length specified in width.
An asterisk (*) means that the width is specified by the associated argument in the argument list, which must be an integer value.</p>
</blockquote>
<p><em>精度</em></p>
<blockquote>
<p>Is the maximum number of characters taken from the argument value for string values. For example, if a string has five characters and precision is 3, only the first three characters of the string value are used.
For integer values, precision is the minimum number of digits printed.
An asterisk (*) means that the precision is specified by the associated argument in the argument list, which must be an integer value.</p>
</blockquote>
<p><em>{h | l}类型</em></p>
<blockquote>
<p>Is used with character types d, i, o, s, x, X, or u, and creates shortint (h) or longint (l) values.</p>
</blockquote>
<p>类型规格</p>
<ul>
<li><code>d
或 i
:有符号整数
o
: 无符号八进制
s
: 字符串
u
: 无符号整数
x
或 X
: 无符号十六进制
在此页面 Sql Server Errors 1-999 上有一个 SQL 服务器错误列表和相关的消息文本。
例如:
Err 2627: Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'.
此异常的示例是:
Violation of UNIQUE KEY constraint 'AK_AdvanceShipmentNotices_CustomerId_PurchaseOrderNumber'. Cannot insert duplicate key in object 'dbo.AdvanceShipmentNotices'. The duplicate key value is (4, 1000).
示例错误文本包含占位符:%ls 和 %.*ls。查看其余的错误示例,还有许多其他占位符,例如%d、%s、%S_DATE、%hs、%S_TS、%x 等等。
问题:这些占位符是在任何地方定义的,还是我只需要自己弄清楚它们的含义?
其他示例错误:
错误 21:警告:发生在 %S_DATE 的致命错误 %d。请记下错误和时间,并联系您的系统管理员。
错误 103:以 '%.*ls' 开头的 %S_MSG 太长。最大长度为 %d。
错误 262:数据库“%.*ls”中的 %ls 权限被拒绝。
Err 407: 内部错误。文件 %hs 中的字符串例程,行 %d 失败,HRESULT 0x%x。
错误 408:在 ORDER BY 列表中遇到常量表达式,位置 %i。
错误 479:table“%.*ls”的 TABLESAMPLE 子句中的 ROWS 值或 REPEATABLE 种子“%I64d”无效。值或种子必须大于 0。
错误 532:时间戳(更改为 %S_TS)显示该行已被另一用户更新。
错误 552:CryptoAPI 函数“%ls”失败。错误 0x%x: %ls
错误 2627:违反 %ls 约束“%.*ls”。无法在对象“%.*ls”中插入重复键。
T-SQL RAISERROR
函数的文档提供了更多信息:
msg_str is a string of characters with optional embedded conversion specifications. Each conversion specification defines how a value in the argument list is formatted and placed into a field at the location of the conversion specification in msg_str. Conversion specifications have this format:
% [[flag] [width] [. precision] [{h | l}]] type
标志
Is a code that determines the spacing and justification of the substituted value.
代码:
-
: 在给定的字段宽度内左对齐参数值。+
:如果值是有符号类型,则在参数值前面加上加号 (+) 或减号 (-)。0
:在输出前加上零,直到达到最小宽度。当出现 0 和减号 (-) 时,忽略 0。#
:当与 o、x 或 X 格式一起使用时,井号 (#) 标志分别在任何非零值前面加上 0、0x 或 0X。当 d、i 或 u 以数字符号 (#) 标志开头时,该标志将被忽略。</code>(空白):如果值是有符号且为正的,则在输出值前加上空格。当包含在加号 (+) 标志中时,它会被忽略。</li> </ul> <p><em>宽度</em></p> <blockquote> <p>Is an integer that defines the minimum width for the field into which the argument value is placed. If the length of the argument value is equal to or longer than width, the value is printed with no padding. If the value is shorter than width, the value is padded to the length specified in width. An asterisk (*) means that the width is specified by the associated argument in the argument list, which must be an integer value.</p> </blockquote> <p><em>精度</em></p> <blockquote> <p>Is the maximum number of characters taken from the argument value for string values. For example, if a string has five characters and precision is 3, only the first three characters of the string value are used. For integer values, precision is the minimum number of digits printed. An asterisk (*) means that the precision is specified by the associated argument in the argument list, which must be an integer value.</p> </blockquote> <p><em>{h | l}类型</em></p> <blockquote> <p>Is used with character types d, i, o, s, x, X, or u, and creates shortint (h) or longint (l) values.</p> </blockquote> <p>类型规格</p> <ul> <li><code>d
或i
:有符号整数o
: 无符号八进制s
: 字符串u
: 无符号整数x
或X
: 无符号十六进制