Using the RAISERROR command in stored procedure

RAISERROR can return either:

    • A user-defined error message that has been created using the sp_addmessage system stored procedure. These are messages with a message number greater than 50000 that can be viewed in the sys.messages catalog view.

    • A message string specified in the RAISERROR statement.

RAISERROR can also:

    • Assign a specific error number, severity, and state.

    • Request that the error be logged in the Database Engine error log and the Microsoft Windows application log.

    • Substitute argument values into the message text, much like the C language printf_s function.

Use RAISERROR WITH LOG to log error to sql server log.

For more info, see:

http://msdn.microsoft.com/en-us/library/ms177497.aspx