Reputation: 1058
I like to be able to enter the following values into my table: 0,0 ; 0,1 ; 1,0 But i want to disable the following value: 1,1
I have made the following query:
CREATE TABLE mytab (a CHAR(1), b CHAR(1), CHECK(a != 1 AND b != 1));
I am able to enter 0,0 but i am unable to enter 1,0. How do i rewrite this logical statement so it does fit my requirements?
Upvotes: 1
Views: 59
Reputation: 1269773
The check constraint should be:
check (not (a = 1 and b = 1))
or equivalently:
check (a <> 1 or b <> 1)
(Actually, these are not exactly equivalent in the presence of NULL
values. The second is probably want you want if you allow NULL
values.)
Upvotes: 3