When Microsoft® SQL Server™ encounters a problem, it either writes a message from the sysmessages system table to the SQL Server error log and the Microsoft® Windows NT® application log, or sends it to the client, depending on the severity level.
Error messages can be either returned by SQL Server when encountering a problem, or produced manually using the RAISERROR statement.
The RAISERROR statement provides centralized error message management. RAISERROR can retrieve an existing entry from sysmessages, or it can use a hard-coded (user-defined) message. When RAISERROR returns a user-defined error message, it also sets a system variable to record that an error has occurred. The message can include C PRINTF-style format strings, which are filled with arguments specified by RAISERROR at run time. After it is defined, the message is sent back to the client as a server error message.
Whether returned by SQL Server or through the RAISERROR statement, each message contains:
For example, if you access a table that does not exist:
SELECT *
FROM bogus
The error message sent to the client looks something like this:
Server: Msg 208, Level 16, State 1
Invalid object name 'bogus'.
You can view the list of SQL Server error messages by querying the sysmessages table in the master database.
For more information about sysmessages, see System Error Messages.
RAISERROR | Using RAISERROR |