Errors raised in Microsoft® SQL Server™ have several attributes:
Each error condition has a unique error number.
The error message gives diagnostic information about the cause of the error. Many error messages have substitution variables in which information, such as the name of the object generating the error, is placed. Every error number has a unique error message.
The severity indicates how serious the error is. Errors with a low severity, such as 1 or 2, are information messages or low-level warnings. Errors with a high severity indicate problems that should be addressed as soon as possible.
Some error codes can be raised at multiple points in the source code for SQL Server. For example, an 1105 error can be raised for several different conditions. Each place the error code is raised assigns a unique state code. A Microsoft support engineer can use the state code from an error to find the location in the source code where that error code is being raised, which may provide additional ideas on how to diagnose the problem.
If the error occurred in a stored procedure, the name of the stored procedure may be available.
The line number indicates which statement in a stored procedure generated the error.
All of the SQL Server errors are stored in the system table master.dbo.sysmessages. User-defined messages can also be stored in sysmessages. The RAISERROR statement can then be used to return these user-defined errors to an application if necessary.
All the database APIs, such as ADO, OLE DB, ODBC, DB-Library, and Embedded SQL, report the basic error attributes: the error number and message string. They vary, however, in how many of the other error attributes they can report.
Other SQL Server components can also raise errors: