The RAISERROR statement provides centralized error message management. User-defined error messages can be added to the sysmessages table by using the sp_addmessage system stored procedure. RAISERROR returns a user-defined error message and sets a system flag to record that an error has occurred (it is no longer necessary to hard code user-defined error messages). RAISERROR can retrieve an entry from sysmessages, or it can use a hard-coded message. The message can include C PRINTF-style format strings, which are filled with arguments specified by RAISERROR at run time. Once defined, the message is sent back to the client as a server error message.
User-defined error message should be given numbers greater than 50000 and severity levels of 0 through 18. Only system administrators can issue RAISERROR with severity level of 19 through 25.
For details on RAISERROR and sp_addmessage, see the Microsoft SQL Server Transact-SQL Reference.