SQL (Oracle) Date Constraints

10 pts.
Tags:
Oracle development
SQL
Can someone tell me how to create a constraint to prevent entering a date prior to 1 Jan 2007? I am tryin g to do it in a create script. Thanks Lock
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi ,
You can use check constraint on column which will check date is grater than 1 jan 2007 or you can create trigger before insert or update which will check that date is grater than 1 jan 2007 .

easy way to use check constraint on column

below is example

CREATE TABLE test
(
log_date DATE CHECK(log_date > to_date(’01/01/2007′ , ‘dd/mm/yyyy’))
)

if table already exists then use

ALTER TABLE test
ADD CONSTRAINT con_chk CHECK(log_date > to_date(’01/01/2007′ , ‘dd/mm/yyyy’))

but for this command to run there should not be single row having date less than 1 jan 2007

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Jerry Lees
    It should be a simple date comparison... .... where date > '1/1/2007' The only tag you have is SQL (oracle) Date Constraints. Do you want this as a SQl statement or someother language, like vbscript. Be sure and check out my blog here on ITKE for more Network administration and VBSCRIPT tips. The VBScript Network and Systems Administrator's Cafe
    5,335 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: