All of the Microsoft® SQL Server™ components can issue informational, warning, or error messages to applications. Most SQL Server messages returned to applications have these parts:
A one-to-five-digit number that identifies the message. Error numbers for user-defined messages can contain more digits.
A Unicode string that contains information about the condition that generated the message.
A one-or two-digit number that indicates the severity of the error condition.
A one-to three-digit number with a maximum value of 127, which indicates to Microsoft support engineers and developers the location in the SQL Server code that generated the message:
The line number within the batch or stored procedure that contains the statement that generated the message.
Line number can also be within the text of the stored procedure that is being executed.
The error numbers, descriptions, and severity levels for most SQL Server messages are stored in master.dbo.sysmessages. The state and line numbers are generated dynamically by the code issuing the message.
Messages raised in the client Net-Libraries, the Microsoft OLE DB Provider for SQL Server, or the SQL Server ODBC driver do not have some of these message parts.
An example of an error message can be seen by executing the statement:
SELECT * FROM ThisObjectDoesNotExist
This statement raises an error with these parts:
Error number: 208
Severity level: 16
State: 1
Line: 1
Description: Invalid object name 'ThisObjectDoesNotExist'.
All of the data APIs used by applications to access SQL Server return the error number and description. Not all of the APIs return the severity level, state, or line number. The OLE DB Provider for SQL Server and the SQL Server ODBC driver return these parts only if an OLE DB or ODBC application has been written to use SQL Server-specific diagnostic features exposed by the provider and driver.