SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to eneter a check constraint with latest date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Thechewinggummonster
Starting Member

United Kingdom
8 Posts

Posted - 11/07/2013 :  13:32:48  Show Profile  Reply with Quote
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

USA
36793 Posts

Posted - 11/07/2013 :  13:40:20  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
22754 Posts

Posted - 11/11/2013 :  03:08:10  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000