sql raiserror指定参数

Dol*_*hin 3 sql sql-server parameters

当我读到MSDN的例子时raiserror:

RAISERROR (N'This is message %s %d.', -- Message text.
           10, -- Severity,
           1, -- State,
           N'number', -- First argument.
           5); -- Second argument.
-- The message text returned is: This is message number 5.
GO
Run Code Online (Sandbox Code Playgroud)

为什么doc使用%s指定 N'number',并 %d指定5- Second参数

MSDN写得像这样:

例如,在下面的RAISERROR语句中,N'number'的第一个参数替换了%s的第一个转换规范; 并且第二个参数5替换了%d的第二个转换规范.

我的问题是:如何解释它?为什么不使用其他类似%a%b.Any其他%+apha可以替代它.我只想得到一个有意义的理解.

Mar*_*ith 7

这表示参数数据类型.

+--------------------+----------------------+
| Type specification |      Represents      |
+--------------------+----------------------+
| d or i             | Signed integer       |
| o                  | Unsigned octal       |
| s                  | String               |
| u                  | Unsigned integer     |
| x or X             | Unsigned hexadecimal |
+--------------------+----------------------+
Run Code Online (Sandbox Code Playgroud)

N'number'是一个nvarchar字符串文字.所以得到说明%s符.字面值5是一个带符号的指示符,因此表示为%d.

至于这些说明者的原因.这在RAISERROR主题中有记录

这些类型规范基于最初为C标准库中的printf函数定义的规范