October 14, 2003 at 8:27 am
Overriding System Messages
All we know the introduction of constraints was a great enhancement to RDBM’S. Look but when you try to violate a constraint, System generates an error message which tells about all most all the stuff but of a little relevance for the end user.
Now let’s have a discussion on
Overriding System Messages
Let me tell my idea In my employees table I am having a Grade filed which references an empgrade table, On the violation of this constraint I wish to get the following error message “Grade field expects a valid grade ” or something like that
Pl contribute
October 14, 2003 at 12:06 pm
You won't be able to override the error message directly. What you can do is trap for an error condition before hand. For instance (within a stored procedure):
IF NOT EXISTS (SELECT grade FROM dbo.ValidGrades WHERE grade = @grade)
BEGIN
RAISERROR('Grade field expects a valid grade.', 14, 1)
RETURN(1)
END
K. Brian Kelley
http://www.truthsolutions.com/
Author: Start to Finish Guide to SQL Server Performance Monitoring
Edited by - bkelley on 10/14/2003 12:06:56 PM
K. Brian Kelley
@kbriankelley
October 15, 2003 at 2:17 am
In that case the very purpose of constraints itself is questioned, each time you have to see in the lookup table means even you can avoid the constraint as a whole. I too know at present the RDBMS’ are not supporting this feature. But I wish to have a discussion on custom messages as part of Constraints or overriding the System Messages.
Frends come forward with new Syntax and Ideas on this Topic
October 15, 2003 at 5:45 am
Here's what I do. I give the constraint a meaningful name, like in your case:
CK_grade_[Grade_field_expects_a_valid_grade].
The user will get a check constraint violation message and also the constraint name, which gives some explanation. Other than that there's nothing more you can do with check constraints in the database.
October 15, 2003 at 7:03 am
The solution to this problem is to handle the error message on the CLIENT side. In other words use structured exception handling, trap the exception and translate the message to a user friendly format.
HTH
* Noel
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply