0

Suppose I am creating a mySQL table with the schema given below-

create table Employee (
emp_id varchar(20) not null unique,
emp_first_name varchar(30) not null,
emp_middle_name varchar(30),
emp_last_name varchar(30) not null,
branch_id int not null,
emp_dob date not null,
designation varchar(30) not null,
emp_gender varchar(10) not null,
emp_address varchar(100) not null,
primary key (emp_id),
foreign key (branch_id) references Branch(branch_id),
constraint chk_emp_gender check (emp_gender in ("male", "female", "other"))
constraint chk_emp_dob check (emp_dob < CURRENT_DATE)  <----- This gives error

);

CURRENT_DATE gives me error as it is equivalent to the function curdate() which is not allowed to be used inside check () constraint.

So, what could be my alternative to achieve this same functionality?

Anant Shekhar
  • 101
  • 1
  • 5
  • CURRENT_DATE() is not deterministic function. So it cannot be used in CHECK constraint. Use trigger. – Akina Mar 18 '23 at 18:12

0 Answers0