CHECK constraint on date of birth?

前端 未结 5 859
南方客
南方客 2020-12-07 02:49

I am creating my employee table in Oracle and for emp_date I would like to make it so the date of birth is not way back in the past and can not be set in the future?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 03:42

    Another way would be to create a domain birthdate, with the constraint built into the domain. This will allow you to reuse the same type in other table definitions.

    CREATE DOMAIN birthdate AS date DEFAULT NULL
        CHECK (value >= '1900-01-01' AND value <= now())
        ;
    
    CREATE TABLE employee
        ( empno INTEGER NOT NULL PRIMARY KEY
        , dob birthdate NOT NULL
        ...
        );
    

提交回复
热议问题