query about check constraint

66 Views Asked by At

want to write a check constraint(while creating a table) which accepts value between 2 dates like ('25-oct-94' to '10-may-16')

2

There are 2 best solutions below

4
Rahul On

Since you are using Oracle you can use CHECK constraint saying

CONSTRAINT check_dates
  CHECK (my_date_column BETWEEN date '1994-10-25' AND date '2016-05-10')

Your query (as in comment) should be like below

 create table dob5 ( birthdate date not null, 
                    CONSTRAINT check_dates 
                    CHECK (birthdate BETWEEN date '1994-10-25' AND date '2016-05-10') );

See this demo fiddle http://sqlfiddle.com/#!4/779f9

1
Ganesh On

please check this.

create table t

( your_columnnm date

check( your_columnnm between date '1994-10-25' and date '2016-05-10' ));