本文介绍了关系数据库设计周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据库设计:

我想添加一个名为Task的新表,它将与一个Project有一对多的关系(项目将有一个或多个任务和特定任务将只属于一个项目)。下一个用户也将被分配到一个项目中的不同任务(基本上用户表需要另一个多对多关系与一个任务,但是在设计中创建一个循环)。这是一个好的做法还是应该避免在设计中产生循环?

I want to add a new table named Task, which would have a one-to-many relationship with a Project(Project will have one or more tasks and particular task will belong to only one project). Next users will also be assigned to different tasks in a project(basically User table needs another many to many relationship with a Task, but that creates a loop in the design). Is this a good practice or should I avoid making loops in a design?

推荐答案

不。

您可能只需要将与特定项目相关的用户分配到特定任务。因此,您需要一个外部键来引用项目的用户,这似乎是奇怪命名的表Project_userprojectrelation。

You probably need only those users who are related to a particular project assigned to specific tasks. So you need a foreign key from tasks to reference the project's users, which seems to be the oddly named table "Project_userprojectrelation".

有时是当你需要级联更新或删除时的麻烦。但是你通常可以从循环的结束或中间向顶部删除行。唯一不起作用的时候是,当你有外键沿着相同的方向在循环上相互追逐。大多数dbms会警告你这种问题。

"Loops" are a nuisance sometimes when you need to cascade updates or deletes. But you can usually delete rows from the "end" or the "middle" of the loop toward the "top". The only time that doesn't work is when you have foreign keys chasing each other around the loop in the same direction. Most dbms's will warn you about that kind of problem.

这篇关于关系数据库设计周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:31
查看更多