Adds a new error message to the sysmessages table.
sp_addmessage [@msgnum =] msg_id,
[@severity =] severity,
[@msgtext =] 'msg'
[, [@lang =] 'language']
[, [@with_log =] 'with_log']
[, [@replace =] 'replace']
Note If a message is written to the Windows NT application log, it is also written to the Microsoft SQL Server™ error log file.
0 (success) or 1 (failure)
None
For localization, the U.S. English version of a message must already exist before the message in another language can be added. The severity of the messages must match.
When localizing messages that contain parameters, use parameter numbers that correspond to the parameters in the original message. Insert an exclamation mark after each parameter number.
Original message | Localized message |
---|---|
‘Original message param 1: %s, param 2: %d’ |
‘Localized message param 1: %1!, param 2: %2!’ |
Because of language syntax differences, the parameter numbers in the localized message may not occur in the same sequence as in the original message.
Execute permission defaults to the public role; however, only members of the sysadmin fixed server role can add messages with a severity level higher than 18 or with with_log set to true.
This example adds a custom message to sysmessages.
USE master
EXEC sp_addmessage 50001, 16,
N'Percentage expects a value between 20 and 100.
Please reexecute with a more appropriate value.'
This example first adds a message in U.S. English and then adds the same message in French.
USE master
EXEC sp_addmessage @msgnum = 60000, @severity = 16,
@msgtext = N'The item named %s already exists in %s.',
@lang = 'us_english'
EXEC sp_addmessage @msgnum = 60000, @severity = 16,
@msgtext = N'L''élément nommé %1! existe déjà dans %2!',
@lang = 'French'
Error Message Severity Levels | sp_dropmessage |
RAISERROR | System Stored Procedures |
sp_altermessage |