2 数据库设计问题。层次树
1.)我有一个数据库,其中每个条目代表一个任务。 而在几十甚至上百个任务中,都会有一个特殊的任务(这是一个里程碑)
因此,在这种情况下,我只有很少的条目需要额外的字段来将它们与大多数条目分开。
我不想创建第二个表,因为这是使这些里程碑变得特别的唯一字段,它们与常规任务条目共享许多其他字段。
我是否应该创建另一个字段来保存一些 TRUE,而其余的默认为 FALSE
2.) 对于每个任务,它都有可变数量的执行者(取决于用户输入) (更进一步,每个执行者都有自己的多个子执行者。)所以我本质上是使用数据库来描述树结构。我现在的方式是,如果有的话,我将拥有相同任务信息的 5 个副本共有5位表演者,占据5个条目。如果我的数据库中不打算有超过 10,000 个条目(包括副本),这是要走的路吗
谢谢
这应该澄清它
任务1(这是一个里程碑任务)
- 表演者1
- 表现不佳 ID=21
- 表现不佳 ID=542
- 表演者2
- 表演者1
任务 2(这不是里程碑任务)
- 表演者2
- 表现不佳 ID=231
- 表演者2
次执行者和执行者是完全不同的群体。完全没有重叠。次要执行者是向执行者提供输入的群体,因此执行者可以完成分配给他们的任务。
1.) I have a DB where each entry represents a task.
And out of several dozens or even a hundred of task, there will be a special task (which is a milestone)
So, in this case, I have very few entries that requires an extra field to separate them from the majority.
I don't want to create a second table, because this is the only fields that makes these milestone stone special, they share a lot of other fields with regular tasks entries.
Should I create another field just to hold a few TRUEs while the rest are FALSE by defaul
2.) For each of those tasks, it has a variable number of performers (depending on user input)
(To further things, each performer has multiple sub-performers of its own.) So I essentially am using a DB to describe a TREE structure.The way I have it now is, I will have 5 copies of the same task info if there are 5 performers, and occupy 5 entries. Is this the way to go if I'm not going to have more than 10,000 entries (incl. copies) in my DB
Thank you
This should clarify it
Task1 (this is a milestone task)
- performer1
- sub-performer ID=21
- sub-performer ID=542
- performer2
- performer1
Task2 (this is not a milestone task)
- performer2
- sub-performer ID=231
- performer2
Subperformer and performer are completely different group. No overlap at all. Subperformer are the group that provide inputs to performer, so performer can complete the task they're assigned to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否是您想要的:
tblTask 包含任务ID、isMilestone 列以及您需要的一切。
tblAgent 包含 agentID 列和您需要的一切(这些将是(子)执行者)。
具有列 fk_agentID、fk_task 的 tblPerformance
具有列 fk_agentID_performer、fk_agentID_subperformer 的 tblSubperformance
被 fk_ 外键引用
I am not sure if this is what you want:
tblTask with columns taskID, isMilestone, and everything you need.
tblAgent with columns agentID and everything you need (these will be the (sub-)performers).
tblPerformance with columns fk_agentID, fk_task
tblSubperformance with columns fk_agentID_performer, fk_agentID_subperformer
Being fk_ foreign keys referencing
1)是创建一个布尔标志。
2)不。如果你有重复的数据,你就会遇到问题。
您需要标准化
1) yes create a boolean flag.
2) no. if you have duplicate data you have a problem.
you need to normalize
您实际上没有利用数据库的关系性质。最好的方法是:
有一个包含两列的表:执行者和次执行者
如果表演者可以 如果表演者可以有多个字段,请在上表中使用表演者 id,并拥有一个包含表演者 id 和其他字段的表
回复:评论
在哪里?这是一个非常奇怪的说法。
第三个表中的重复不是冗余问题,因为您没有复制任何信息:表中的信息与关系有关,并且三行中有三个关系。
当您有像您这样的设置时,就会出现冗余问题,假设任务 143 的完成日期为“2011 年 5 月 31 日”,那么您的表格将如下所示:
现在假设我想更改
completion-date 对于任务 143。在您的设置中,我必须在所有三行中更改它,更糟糕的是,如果有人做错了什么,您可能会得到一个不一致的表,例如:
现在您不知道哪一个是正确的
completion_date
!当您标准化时,一个表中只有一行可以更改日期,并且您的数据库永远不会像这样不一致。
You're really not exploiting the relational nature of databases. The nice way to do it is:
Have a table with two columns: performer and sub-performer
If a performer can have multiple fields, use a prerformer id in the tables above and have a table with performer id and other fields
Re: Comment
Where? It's a pretty strange claim.
The repetition in the third table isn't a redundancy problem because you aren't replicating any information: the information in the table is about relationships and there are three relationships in three rows.
A redundancy problem appears when you have a setup like yours, were, let's say task 143 has a completion_date "May 31, 2011" then your table would look like:
Now let's say I want to change the
completion-date
for task 143. In your setup I have to change it in all three rows, and what's worse, if someone does something wrong you could get an inconsistent table like:And now you don't know which is the right
completion_date
!When you normalize, you only have one row in one table to change the date, and your database is never inconsistent like that.