MSSQLCity.Com - All about MS SQL
     
About Us  
SSWUG Articles  
Articles  
FAQ  
Administration  
Backup/Restore  
Connectivity  
Development  
General  
Installation  
OLAP  
Replication  
Transfer/move  
Trouble  
SQL 6.5  
Scripts  
Tips  
Test Exams  
Advertise  
Download  
History  
Search  
Traffic  
Related Links  
     
Your button logo
Add to Favorites
 
     
 


How can I add a user-defined error message?

Answer:

You can use the sp_addmessage system stored procedure to add a user-defined error message.

You can specify the id of the message (value greater than 50000), severity level from 0 through 25 (to add a message with a severity level from 19 through 25, you must be a member of the sysadmin fixe server role) and the message text (up to 255 characters).

By the way, only members of the sysadmin and serveradmin fixed server roles can execute the sp_addmessage system stored procedure.

This is the example:

USE master
EXEC sp_addmessage @msgnum = 50001,
                   @severity = 18,
                   @msgtext = 'Custom error message'
See SQL Server Books Online for more details about the sp_addmessage system stored procedure.


 

 
Visit The SQL Server Worldwide User's Group for all the latest news and information about SQL Server, Oracle, DB2 and XML for developers and administrators.

(c) 1997, 2005 Bits on the Wire, Inc