November 18, 2003 at 10:29 am
I have several check constraints in place. E.g. len (Field1) = 6
Is there a way of specifying a user-defined message when a particular constraint is violated? So for each constraint, there will be a unique message that relates to the violation. Can any thing other than triggers achieve this?
NB I do not want to change the message in sysmessages.
November 18, 2003 at 10:49 am
Form the section "Triggers Compared to Constraints" in BOL Article "Enforcing Business Rules with Triggers"
quote:
Constraints can communicate about errors only through standardized system error messages. If your application requires (or can benefit from) customized messages and more complex error handling, you must use a trigger.
November 19, 2003 at 1:33 am
You can put a short message inside the name of CK. When a user reads a violation message, he will see that message too. I do it like this:
CK_Table_1_[_Field_length_must_be_6_]
-where CK= Check Constraint, Table = table name, 1 = the number of CK on this table, if you have several, you only need the user to tell you the number, not the whole message, [] = message inside paretheses.
Try it, if a user carefully looks at the error message he will see your note.
That's as far as it goes without triggers.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy