When i read the example of 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
Why the doc using %s
to specify the N'number'
,and %d
to specify the 5
-- Second argument
The MSDN write like this:
For example, in the following RAISERROR statement, the first argument of N'number' replaces the first conversion specification of %s; and the second argument of 5 replaces the second conversion specification of %d.
My question is: How can explain it? Why don't using other like %a
or %b
.Any other %+apha
can replace it.
I just want to get a meaningful understand.
Is an integer from 0 through 255. Negative values default to 1. Values larger than 255 should not be used. If the same user-defined error is raised at multiple locations, using a unique state number for each location can help find which section of code is raising the errors.
Therefore, when a system error occurs, SQL Server will log a system error and may take actions to fix the error. Custom errors, on the other hand, are generated by T-SQL custom codes based on your code or business logic. To add a custom error message to sys. messages, the stored procedure sp_addmessage is used.
Differences Between RAISERROR and THROWIf a msg_id is passed to RAISERROR, the ID must be defined in sys. messages. The error_number parameter does not have to be defined in sys. messages.
This represents the parameter datatype.
+--------------------+----------------------+
| Type specification | Represents |
+--------------------+----------------------+
| d or i | Signed integer |
| o | Unsigned octal |
| s | String |
| u | Unsigned integer |
| x or X | Unsigned hexadecimal |
+--------------------+----------------------+
N'number'
is an nvarchar
string literal. So gets the %s
specifier. And the literal 5
is a signed indicator so is represented by %d
.
As for the reason for these specifiers. This is documented in the RAISERROR
topic
These type specifications are based on the ones originally defined for the printf function in the C standard library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With