You are on page 1of 2

MSSQL Error analysis

 The error/info/warning messages are passed to the client application.


 It's the client application responsibility to format them and present them to the user.
 All MSSQL error messages have the same structure:

Category Explanation
Message number Most system messages are stored in the MASTER database, table
< 50000 SYSMESSAGES by message number
Message number Programmer defined messages stored in the MASTER database,
> 50000 table SYSMESSAGES by message number
Severity level A number between 0 and 25
A number between 0 and 10: It's either an information message or a
Severity level
warning message.
Severity level A number between 11 and 16: It's a SQL programming error.
A number between 17 and 25: It's a resource problems, hardware
Severity level
problems or internal problems in SQL Server.
State A number between 0 and 127: Undocumented by Microsoft
Name of the stored procedure, trigger or user-defined function that
Procedure
the error occurred.
Procedure Blank if the error occurred in an interactive SQL statement.
Line number within the procedure/function/trigger/batch the error
Line
occurred.
Line number equal 0 means that the problem occurred when the
Line
procedure/function/trigger was invoked.
The actual text of the message. It should give you an indication of
Message text
what is the problem.
Custom error messages
You can create you own error messages with:

sp_addmessage

The customer error message, starts at: 50001

You can create error messages on the fly with:

RAISERROR('Test message #1', 16, 1);


go
Msg 50000, Level 16, State 1, Line 2
Test message #1
RAISERROR('Test message #4', 4, 3);
go
Test message #4
Msg 50000, Level 4, State 3

 The severity decides the colour: red = error, black = warning/info.


 Notice the error message # before the message.
 Notice the info message # after the message.

You might also like