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.