I need to check datecom
is less than datelivr
create table Commande
(
Numcom int identity primary key,
Datecom date,
Datelivr date,
Codecli int foreign key references clients (Codecli)
)
alter table Commande
add constraint date_check check(datediff(day,Datecom,Datelivr) > 0)
but I get the error message:
The ALTER TABLE statement conflicted with the CHECK constraint
"date_check". The conflict occurred in database "tp4", table
"dbo.Commande".
How can this happen?
Best Answer
The error message is self-explanatory: Your check constraint is trying to enforce that all values in
Datecom
are at least one day earlier thanDatelivr
, but you must have at least one row where this is not true - eitherDatecom
is the same day, later, or one of the values isNULL
. Find those rows using: