我的应用程序从4年前就开始使用了。我有一个桌子结构,我怀疑这是最好的做法。如果我以后有空的话,我想修好它。
这是我最近的设计:
tbl_echelon2:
+----+------------------------+
| id | name |
+----+------------------------+
| 1 | Public Relation Bureau |
+----+------------------------+tbl_echelon3:
+----+------------+-------------+
| id | name | echelon2_id |
+----+------------+-------------+
| 1 | Division A | 1 |
| 2 | Division B | 1 |
+----+------------+-------------+tbl_echelon3:
+----+--------------------+-------------+
| id | name | echelon3_id |
+----+--------------------+-------------+
| 1 | SubDivision 1 of A | 1 |
| 2 | SubDivision 2 of A | 1 |
| 3 | SubDivision 1 of B | 2 |
| 4 | SubDivision 2 of B | 2 |
+----+--------------------+-------------+tbl_position:
+----+---------------------+
| id | name |
+----+---------------------+
| 1 | Head of Bureau |
| 2 | Head of Division |
| 3 | Head of SubDivision |
| 4 | Staff |
+----+---------------------+下面是我想要获得最佳实践的表格
tbl_employee:
+----+---------+-------------+------+------+------+
| id | name | position_id | ech2 | ech3 | ech4 |
+----+---------+-------------+------+------+------+
| 1 | Andrew | 1 | 1 | | | Head of Public Relation Bureau
| 2 | Beyonce | 2 | 1 | 1 | | Head of Division A
| 3 | Cody | 2 | 1 | 2 | | Head of Division B
| 4 | Dan | 3 | 1 | 1 | 1 | Head of SubDivision 1 of A
| 5 | Ernest | 3 | 1 | 1 | 2 | Head of SubDivision 2 of A
| 6 | Frans | 3 | 1 | 2 | 1 | Head of SubDivision 1 of B
| 7 | Graham | 3 | 1 | 2 | 2 | Head of SubDivision 2 of B
| 8 | Hardy | 4 | 1 | 1 | 1 | staff of SubDivision 1 of A
| 9 | Irwin | 4 | 1 | 2 | 2 | staff of SubDivision 2 of B
+----+---------+-------------+------+------+------+我的问题是:如何在这个案子上做最好的实践?我的设计可以接受吗?
当前应用程序的后端是Server数据库;但是,正在开发的版本将使用MySQL。
发布于 2018-03-08 10:47:09
如果你需要第五个梯队会发生什么?如果一个员工在一个以上的部门中有一个角色,该怎么办?
一个更小、更简单的模式应该涵盖您的业务案例,并且需要更少的工作来实现、维护和扩展。例如:
Employee (id, name)
Division (id, name, subdivision_of)
[subdivision_of -> Division.id]
Position (id, name)
Role (employee_id, division_id, position_id)
[
employee_id -> Employee.id,
division_id -> Division.id,
position_id -> Position.id
]如果您不希望一个人能够在多个部门工作,我想您可以声明employee_id是唯一的。
编辑:我看到的另一个问题是employee表中的冗余异常。它重复有关部门等级的信息。如果您更改了该结构,则必须记住遍历employees表中的每一行,以确保更改在那里得到反映。
https://dba.stackexchange.com/questions/199646
复制相似问题