Adds user-defined messages to sysusermessages for use by stored procedure print and raiserror calls and by sp_bindmsg.
sp_addmessage message_num, message_text [, language [, with_log [, replace]]]
sp_addmessage 20001, "The table '%1!' is not owned by the user '%2!'."
sp_addmessage 20002, "The procedure'%1!' is not owned by the user '%2!'.", NULL, TRUE, "replace"
sp_addmessage does not overwrite an existing message of the same number and langid unless you specify @replace = “replace".
print and raiserror recognize placeholders in the message text to print out. A single message can contain up to 20 unique placeholders in any order. These placeholders are replaced with the formatted contents of any arguments that follow the message when the text of the message is sent to the client.
The placeholders are numbered to allow reordering of the arguments when the SAP ASE server is translating a message to a language with a different grammatical structure. A placeholder for an argument appears as “%nn!”, a percent sign (%), followed by an integer from 1 to 20, followed by an exclamation point (!). The integer represents the argument number in the string in the argument list. “%1!” is the first argument in the original version, “%2!” is the second argument, and so on.
Only the user who created a message can execute sp_addmessage with the replace option to replace that original message.
See also print, raiserror in Reference Manual: Commands.
The permission checks for sp_addmessage differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, any user can execute sp_addmessage. To add a message with with_log, you must be the database owner or a user with own database privilege on the database. |
Disabled | With granular permissions disabled, any user can execute sp_addmessage. To add a message with with_log, you must be the database owner or a user with sa_role. Only the user who created the message can execute sp_addmessage with the replace option to replace that original message. |
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 15 |
Audit option | create |
Command or access audited | sp_addmessage |
Information in extrainfo |
|