MYSQL проверка значения поля перед вставкой
Есть 2 таблицы:
create table team
(
employee_id bigint not null,
project_id bigint not null,
role_id int not null,
foreign key (employee_id) references employee (id),
foreign key (project_id) references project (id),
foreign key (role_id) references role (id)
);
в которой хранятся id сотрудников employee_id
id проектов project_id
и id роли сотрудника в проекте role_id
Также имеется таблица task
:
create table task
(
id bigint primary key auto_increment,
name varchar(30) not null,
description text,
executor_id bigint,
labor_costs int not null,
deadline date not null,
status_id int not null,
author_id bigint,
date_of_creation date not null,
update_time date,
foreign key (executor_id) references employee (id),
foreign key (status_id) references task_status (id),
foreign key (author_id) references employee (id),
executor_id
в таблице task
показывает id сотрудника, который выполняет поставленную задачу.
Выполнять поставленную задачу может только сотрудник,который участвует в проекте. Т.е перед вставкой значения в executor_id
нужно направить запрос в team
и посмотреть, участвует ли указанный executor_id
в нашем project_id
.
Как можно добиться такой проверки перед вставкой значения в бд?Т.е необходимо написать check