开发者

check constraint for date

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)
     );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜