I’m in training period and my trainer gave me some database exercises.
I have to make Project, Employee, Roles and Employee_Projects_Role tables. Last table has the details of the employees working on a project with a specified role.
The conditions he gave to me are:
1. One employee can work in multiple projects.
2. One employee can not have different roles in same projects.
I made those tables and inserted the data. In roles, I had roles Leader, Manager, Developer. I made those tables and entered the data.
He checked my tables and said that a project have more than 1 leader and 1 manager so I restricted the columns like there wont be same roles in one project but now I can not enter 2 developer to that mapping table in one project.
But a project can obviously has 2 developers. So, If you understand the whole scenario then I want to ask that is that possible to restrict a particular column that it would be having only one leader and manager in one project?
I am not really into database but before assigning me a project work he wants to just brush up my basics. So, I am really confused in that.
Schema for those tables is as following:
-
Project with following fields :
project_pid – primary key,
project_name -
Employee with following fields:
employee_pid – primary key,
employee_name,
gender – M/F,
salary,
date_of_joining,
is_active – Y/N -
Roles with following fields:
role_pid – primary key,
role_name – (team member or leader) -
Employee_Project_Role with following fields:
project_xid – foreign key (references table Projects),
employee_xid – foreign key (references table Employee),
role_xid – foreign key (references table Roles)
To implement such logic, you need to use procedural language. The easiest way in my opinion is defining a trigger: