Error Messages
When Microsoft® SQL Server™ 2000 encounters a problem, it either writes a message from the sysmessages system table to the SQL Server error log and the Microsoft Windows® 2000 or Microsoft Windows NT® 4.0 application log, or sends a message 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 that 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:
- A message number that uniquely identifies the error message.
- A severity level that provides an indication of the type of problem.
- An error state number that identifies the source from which the error was issued (if the error can be issued from more than one place).
- A message that states the problem and sometimes a possible solution.
For example, if you access a table that does not exist:
SELECT *
FROM bogus
The error message sent to the client looks similar to 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.