简体   繁体   中英

Database design for employee, department and role hierarchy

Suppose I have employees and departments and employee role where one employee can belong to a different department with a different role.

For example, Emp 1 belongs to Dept 1 with a role manager. where the same employee can belong to Dept 2 with a role service-man.

Each employee also has a child hierarchy like Emp 2, Emp 3 belongs to Dept 1 with role assistant and their parent is Emp 1.

In this case what will be the best solution for designing this concept. Please share your opinion.

Consider the entities and attributes:

Employees: id, name

Departments: deptID, dept_name

Roles: role_id, role_name

I'll try to state the business domain as you've outlined it, and then turn that into a schema suggestion.

The system has 0 or more employees

The system has 0 or more departments

The system has 0 or more roles <<EDIT: your comment says that the "parent" role is department-specific>> An employee belongs to 1 or more departments , and within that department has exactly one role and one parent (a parent is another employee)

Employee
------------
Employee_id (pk)
Name

Roles
------
Role_id (pk)
Name

Departments
-----------
Department_id (pk)
Name

Employee_deparment_role
-------------------------
employee_id (pk, fk)
department_id (pk, fk)
role_id (pk, fk)
Parent_id (pk, fk to employees) 

This model only captures one state - it doesn't allow people to change departments or roles, or "parent", but you didn't mention that as a requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM