Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check constraints

Status
Not open for further replies.

gojohnnygogogogo

Programmer
May 22, 2002
161
GB
hello,
How would I create a check constraint to make sure that before inserting the start date is less than the end date ?

Also can I use this to display a message on an asp page telling the user the data is incorrect, or would I need to do validate the data on the asp page aswell. ?

thank you for any info.

Cheers.
 
IMHO, I would validate on the ASP page. This is a fairly simple validation; why make a round trip to the server? You could still create the CONSTRAINT:

--Create the table with the constraint
create table #angel
(startdate datetime not null,
enddate datetime not null,
CONSTRAINT ChkDates CHECK (startdate < enddate))

--This works fine
insert #angel select '1/1/2002','2/1/2002'
--This gives a constraint violation
insert #angel select '3/1/2002','2/1/2002'
--Angel
-----------------------------------
SELECT * FROM users WHERE clue > 0
(0 row(s) affected)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top