开发者

check constraint for date

开发者 https://www.devze.com 2023-03-05 02:06 出处:网络
I need a check constraint for date so no data can be entered after tod开发者_开发百科ay\'s/this 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

精彩评论

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

关注公众号