erd - ER Diagram 1:N relationship Convert
问题描述
If I have Employees and project and relationship one-to-many (many for projects i.e Employees can be assigned to multiple projects and one project is assigned to exactly one employee) the table will be:
Employees (empid,name,phone)
Projects(proid,proname,cost,empid)
can I move proid key to employees table as :
Employees(empid,name,phone,proid)
Projects(proid,proname,cost)
This convert will be wrong or still right? and if the last convert is wrong, why it's wrong?
解决方案
您必须将其添加empid
到Projects
表中。当您将proid
列添加到Employees
表中时,您只能引用一个项目。如果你有一个员工分配到多个项目,你会得到这样的东西:
Employees(1, "John", "123-456-789", 42)
Employees(1, "John", "123-456-789", 20)
如您所见,您的表中有两次员工,更不用说违反主键了。因此,您必须将员工 ID 保存在Projects
表中。
Projects(42, "Research", 10000, 1);
Projects(20, "Analysis", 3000, 1);
推荐阅读
- imagemagick - 通过启动图像来反转变形
- awk - 根据文件中列中的值拆分大文件
- clojure - 使用石英岩的 cron 示例时得到“clojurewerkz.quartzite.jobs/of-type 的不正确 arity 1”?
- c - 使用 c 程序更改应用程序核心转储目录
- r - 当使用 `scale_colour_manual` 或替代方法(有时)缺少因子水平时,`ggplot2` 中的一致着色
- gradle - grails 应用程序的引导运行失败,但构建成功
- android - 使用选项卡将数据传输到 ViewPager
- html - 错误:未捕获(承诺中):错误:无法分配给引用或变量
- python - sklearn中ROC曲线的AUC
- html - 如果使用 www.something.com,为什么标签无法正确导航到 url