Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to eneter a check constraint with latest date

Author  Topic 

Thechewinggummonster
Starting Member

8 Posts

Posted - 2013-11-07 : 13:32:48
Without having to update it every day.

This is so no one enters a value higher than the current date.

ALTER TABLE Persons
ADD CONSTRAINT chk_Person CHECK (Closed_Date>)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-11-07 : 13:40:20
Take a look at the GETDATE() function.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-11-11 : 03:08:10
One method is


ALTER TABLE #Persons
ADD CONSTRAINT chk_Person CHECK (Closed_Date<=getdate())

If the TIME part is not a problem, you can do


ALTER TABLE #Persons
ADD CONSTRAINT chk_Person CHECK (Closed_Date<=dateadd(day,datediff(day,0,getdate()),1))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -