I have a table with two linked columns, a compulsory boolean and an optional date. There can only be a date when the boolean is FALSE. So I have this structure:
CREATE TABLE FOO (
FOO_ID INT IDENTITY(1, 1) NOT NULL,
MY_DATE DATETIME,
MY_BOOLEAN BIT DEFAULT 0 NOT NULL,
CONSTRAINT FOO_PK PRIMARY KEY (FOO_ID)
);
And I've written this constraint to keep the data integrity:
ALTER TABLE FOO
ADD CONSTRAINT FOO_CHK CHECK (
MY_BOOLEAN=0 OR MY_DATE IS NULL
);
I must be missing something obvious but the fact is that I cannot run this update query:
UPDATE FOO
SET
MY_BOOLEAN=1,
MY_DATE=NULL
WHERE FOO_ID=31416
I get a check constraint conflict error and the update fails. What am I doing wrong?
UPDATE
I regret to inform that I had mistyped a column name... Sorry for wasting your time. I wish I could remove the question :_(