I am trying to make a constraint to ensure that the finishdate
is at least 3 years greater than the startdate
.
I have had a look around but really do not know where to start?
Would i need to use a dateadd
function?
Thanks
I am trying to make a constraint to ensure that the finishdate
is at least 3 years greater than the startdate
.
I have had a look around but really do not know where to start?
Would i need to use a dateadd
function?
Thanks
You could do it a number of ways, but since you asked about check constraints, something like this should work:
CREATE TABLE myTable
(
id numeric(4),
startdate date,
finishdate date,
CONSTRAINT check_date
CHECK (finishdate >= add_months( startdate , 36 ))
);