February 11, 2009 at 10:59 am
Can I use a check constraint to enforce the business rule that if one field is populated then another field must be null?
e.g. if field AAA is not null then field BBB must be null
and if field BBB is not null the field AAA must be null
February 11, 2009 at 12:05 pm
I've managed to solve my own problem. It was easier than I thought, I've just never done anything like that before.
It amounts to;
CONTSTRAINT One_or_the_Other CHECK ((AAA IS NULL AND BBB IS NOT NULL) OR (AAA IS NOT NULL AND BBB IS NULL))
February 12, 2009 at 1:53 pm
[font="Verdana"]Actually, this is a good example of what I most commonly use check constraints for. Some sort of dependency between the columns in the table. The other common use I make is where I have a column that needs a specific format or range.[/font]
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply