简体   繁体   English

员工、部门和角色层次结构的数据库设计

[英]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.例如,Emp 1 属于具有角色经理的 Dept 1。 where the same employee can belong to Dept 2 with a role service-man.同一员工可以属于具有服务人员角色的 Dept 2。

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.每个员工还有一个像 Emp 2 这样的子层次结构,Emp 3 属于具有角色助手的 Dept 1,其父级是 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部门:deptID、dept_name

Roles: role_id, role_name角色: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.我将尝试 state 您概述的业务域,然后将其转换为模式建议。

The system has 0 or more employees系统有0个或多个员工

The system has 0 or more departments系统有0个或多个部门

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)系统有 0 个或多个角色<<编辑:您的评论说“父”角色是特定于部门的>>员工属于 1 个或多个部门,并且在该部门内只有一个角色和一个级(父级是另一名员工)

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.此 model 仅捕获一个 state - 它不允许人们更改部门或角色或“父母”,但您没有提到这是一项要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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