Transact SQL – User defined error messages

Background

Quickly, how to identify user defined error messages.

Guide Post

Here is the Link :-

Docs / SQL / Relational databases / System stored procedures
sp_addmessage (Transact-SQL)
Link

@msgnum = ] msg_id
Is the ID of the message. msg_id is int with a default of NULL. msg_id for user-defined error messages can be an integer between 50,001 and 2,147,483,647.

Explanation

To defined a new error, we have to specify a message id greater than 50001.  Or pass along null, and an id greater than 50001 will be assigned to us.

Code

Outline

  1. sys.messages
    • messsage_id >=50001

SQL


select
          tblSM.[message_id]

        , tblSM.[language_id]

        , tblSM.[severity]

        , tblSM.[is_event_logged]

        , tblSM.[text]

        , [customized]
            = case
                when (tblSM.[message_id] >= 50001) then 'Y'
                else 'N'
               end	

from   sys.messages tblSM

where  tblSM.[message_id] >= 50001

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s