CHECK constraint on date of birth?

前端 未结 5 867
南方客
南方客 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条回答
  •  猫巷女王i
    2020-12-07 03:26

    You can use interval directly:

    ALTER TABLE "students"
      ADD CONSTRAINT "students_must_be_over_18" CHECK (
        CURRENT_TIMESTAMP - "date_of_birth" > INTERVAL '18 years'
      );
    

提交回复
热议问题