Обсуждение: Constraint

Поиск
Список
Период
Сортировка

Constraint

От
"João" Paulo Batistella
Дата:
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

Re: Constraint

От
Stephan Szabo
Дата:
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.