I need a check constraint for date so no data can be entered after tod开发者_开发百科ay's/this date.
please advise thanks all
Try this:
ALTER TABLE yourTable
ADD CONSTRAINT yourDateTimeColumn CHECK (yourDateTimeColumn < GetDate() );
To remove the time part on SQL Server 2008, use cast...date
Also, I assume you can have dates including today
ALTER TABLE yourTable
ADD CONSTRAINT yourDateTimeColumn CHECK (
CAST(yourDateTimeColumn as date) <= CAST(GETDATE() as date)
);
精彩评论