Constraint

Started by Jo�oover 23 years ago2 messagesgeneral
Jump to latest
#1Jo�o
batistellabr@yahoo.com.br

Hi.

I would like to make the following constraint in my
db.

I have three fields:
-field1
-field2
-field3

If field1 is not null, then field2 and field3 MUST be
null. Again, if field2 is not null, then field1 and
field3 MUST be null, and so on...

Is it possible?
How can I do that?

Thanks,
JP

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Jo�o (#1)
Re: Constraint

On Tue, 16 Jul 2002, Jo�o Paulo Batistella wrote:

Hi.

I would like to make the following constraint in my
db.

I have three fields:
-field1
-field2
-field3

If field1 is not null, then field2 and field3 MUST be
null. Again, if field2 is not null, then field1 and
field3 MUST be null, and so on...

Is it possible?
How can I do that?

Should be possible with a table check constraint.
There's probably a better way, but:

check(
(a is not null and b is null and c is null) or
(b is not null and a is null and c is null) or
(c is not null and a is null and b is null)
)

If they can all be null, you need an additional
clause to say that.