Home » SQL & PL/SQL » SQL & PL/SQL » Re: Maximum default value for a DATE in a table?
Re: Maximum default value for a DATE in a table? [message #1822] Sun, 02 June 2002 22:07
Maaher
Messages: 7065
Registered: December 2001
Senior Member
You can assign a Default value, but as the word says: it is a DEFAULT. In your case, to verify a date is not bigger than a maximum, I would use a check constraint. The syntax is something like this:
ALTER TABLE MHE_TEST
 ADD CONSTRAINT CHK_MAX_DATE CHECK (col_date < to_date('31-12-2020','DD-MM-YYYY'))
/


This constraint makes sure the maximum date will not be exceeded:
SQL> insert into mhe_test values (to_date('12-01-2021','DD-MM-YYYY'));
insert into mhe_test values (to_date('12-01-2021','DD-MM-YYYY'))
            *
ERROR at line 1:
ORA-02290: check constraint (MHE.CHK_MAX_DATE) violated


HTH,
MHE
Previous Topic: help this baby user
Next Topic: Re: working with dates
Goto Forum:
  


Current Time: Thu Apr 18 19:43:54 CDT 2024