我需要设计数据库,这将保存有关员工的信息。他们可能分为几类:演员,导演或音乐家。这些类别也可能在某些类别上有所不同。所以,我有员工类别的树。我有性能表,必须有导演的外键。
我可以制作表,其中包含有关员工的常用信息,并且具有类别树的表的外键吗?它会是正确的吗?
employee_categorie
+-----------------+----------+
| name | encoding |
+-----------------+----------+
| actor | 1 |
| subactor1 | 1.1 |
| subactor2 | 1.2 |
| director | 2 |
| first_director | 2.1 |
| second_director | 2.2 |
+-----------------+----------+
employee
+-------------+------------+-----------+-----------------------+
| employee_id | first_name | last_name | employee_categorie_id |
+-------------+------------+-----------+-----------------------+
| 1 | Joshu | Willis | 1.1 |
| 2 | Genry | Ford | 2.1 |
| 3 | Jeff | Bridge | 1.2 |
| 4 | Silvester | Obama | 2.2 |
| 5 | Mark | Watney | 2.2 |
+-------------+------------+-----------+-----------------------+
performance
+----------------+------------------+-------------------------+
| performance_id | performance_name | performance_director_id |
+----------------+------------------+-------------------------+
| 1 | Godzilla | 5 |
| 2 | Alice | 4 |
| 3 | God is dead | 5 |
+----------------+------------------+-------------------------+
抱歉我的英语不好。
答案 0 :(得分:1)
根据我们在评论中的对话,我建议为performance_employees添加一个表:
performance_employees
+----------------+-------------+-------------+
| performance_id | employee_id | category_id |
+----------------+-------------+-------------+
| 1 | 1 | 1.1 |
| 1 | 2 | 2.1 |
| 1 | 3 | 1.2 |
+----------------+-------------+-------------+
并在性能表中为actor添加一个外键到该表。另外,将检查约束添加到性能表中,以确保director列实际指向a类别id指向director的记录。