I have a table with two related columns, a required logical and optional date. There can only be a date when the boolean value 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 wrote this restriction to maintain data integrity:
ALTER TABLE FOO
ADD CONSTRAINT FOO_CHK CHECK (
MY_BOOLEAN=0 OR MY_DATE IS NULL
);
I have to miss something obvious, but the fact is that I cannot run this update request:
UPDATE FOO
SET
MY_BOOLEAN=1,
MY_DATE=NULL
WHERE FOO_ID=31416
I get a validation constraint conflict error and the update does not work. What am I doing wrong?
UPDATE
I regret to inform you that I was mistaken in the column name ... Sorry for wasting time. I would like to remove the question: _ (
source
share