Reputation: 37
SQL Server 2014 issue. I created a table which has two DATE columns with DATE datatypes. One is populated the other is a future event. I created a constraint that date1 < date2. I inserted into the table putting NULL into date2 because it is future. I cannot update anything in the table. When trying to update date2 with date, I get Operand type clash: int is incompatible with date. I tried entering date with and without apostrophes in ever way I could think of. I cannot drop or alter the column because of the constraint I added. HELP. Please be specific about the SQL syntax needed for altering or updating to fix.
Upvotes: 1
Views: 49
Reputation:
You should use single quotes '2019-04-18' with the ' before and after.
Upvotes: 0
Reputation: 1270713
Change the constraint! It is never true -- either false or NULL
. So, remove the constraint you have and do something like:
alter table t add constraint chk_t_date1_date2 check ( (date1 < date2) or date2 is null);
To drop the constraint, you do:
alter table t drop constraint <constraint name>;
You need to know the name of the constraint, which you can get from information_schema.table_constraints
.
Upvotes: 0