2 数据库设计问题。层次树

发布于 2024-11-11 04:22:50 字数 700 浏览 4 评论 0原文

1.)我有一个数据库,其中每个条目代表一个任务。 而在几十甚至上百个任务中,都会有一个特殊的任务(这是一个里程碑)
因此,在这种情况下,我只有很少的条目需要额外的字段来将它们与大多数条目分开。

我不想创建第二个表,因为这是使这些里程碑变得特别的唯一字段,它们与常规任务条目共享许多其他字段。

我是否应该创建另一个字段来保存一些 TRUE,而其余的默认为 FALSE

2.) 对于每个任务,它都有可变数量的执行者(取决于用户输入) (更进一步,每个执行者都有自己的多个子执行者。)所以我本质上是使用数据库来描述树结构。我现在的方式是,如果有的话,我将拥有相同任务信息的 5 个副本共有5位表演者,占据5个条目。如果我的数据库中不打算有超过 10,000 个条目(包括副本),这是要走的路吗

谢谢

这应该澄清它

  1. 任务1(这是一个里程碑任务)

    • 表演者1
      • 表现不佳 ID=21
      • 表现不佳 ID=542
    • 表演者2
  2. 任务 2(这不是里程碑任务)

    • 表演者2
      • 表现不佳 ID=231

次执行者和执行者是完全不同的群体。完全没有重叠。次要执行者是向执行者提供输入的群体,因此执行者可以完成分配给他们的任务。

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

  1. Task1 (this is a milestone task)

    • performer1
      • sub-performer ID=21
      • sub-performer ID=542
    • performer2
  2. Task2 (this is not a milestone task)

    • performer2
      • sub-performer ID=231

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绳情 2024-11-18 04:22:50

我不确定这是否是您想要的:

tblTask​​ 包含任务ID、isMilestone 列以及您需要的一切。

tblAgent 包含 agentID 列和您需要的一切(这些将是(子)执行者)。

具有列 fk_agentID、fk_task 的 tblPerformance

具有列 fk_agentID_performer、fk_agentID_subperformer 的 tblSubperformance

被 fk_ 外键引用

fk_agent -> tblAgent.agentID
fk_task -> tblTask.taskID
fk_agentID_performer -> tblAgent.agentID
fk_agentID_subperformer -> tblAgent.agentID

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

fk_agent -> tblAgent.agentID
fk_task -> tblTask.taskID
fk_agentID_performer -> tblAgent.agentID
fk_agentID_subperformer -> tblAgent.agentID
轻许诺言 2024-11-18 04:22:50

1)是创建一个布尔标志。

2)不。如果你有重复的数据,你就会遇到问题。
您需要标准化

1) yes create a boolean flag.

2) no. if you have duplicate data you have a problem.
you need to normalize

那小子欠揍 2024-11-18 04:22:50

您实际上没有利用数据库的关系性质。最好的方法是:

  • 有一个任务表(具有唯一的 id,没有额外的里程碑字段,没有 preformers)
  • 有一个包含两列的里程碑表:任务 id 和特殊的里程碑字段 - 只有里程碑才会出现在该表中
  • 有一个包含两列的表:任务 ID 和执行者
  • 有一个包含两列的表:执行者和次执行者

  • 如果表演者可以 如果表演者可以有多个字段,请在上表中使用表演者 id,并拥有一个包含表演者 id 和其他字段的表

回复:评论

我读到规范化会降低数据库效率,这就是我将它们全部结合起来的原因。

在哪里?这是一个非常奇怪的说法。

对于包含任务 ID 和执行者的表(列表中的第三个),如果任务 143 需要员工 A、B、C。在 DB 中,(第 1 行 | 143 | A)(第 2 行 | 143) | B) (第 3 行| 143 | C) 你们还有冗余吗?

第三个表中的重复不是冗余问题,因为您没有复制任何信息:表中的信息与关系有关,并且三行中有三个关系。

当您有像您这样的设置时,就会出现冗余问题,假设任务 143 的完成日期为“2011 年 5 月 31 日”,那么您的表格将如下所示:

task_id  completion_date  performer
143      May 31, 2011     A
143      May 31, 2011     B
143      May 31, 2011     C

现在假设我想更改 completion-date 对于任务 143。在您的设置中,我必须在所有三行中更改它,更糟糕的是,如果有人做错了什么,您可能会得到一个不一致的表,例如:

task_id  completion_date  performer
143      May 31, 2011     A
143      May 12, 2011     B
143      May 31, 2101     C

现在您不知道哪一个是正确的completion_date
当您标准化时,一个表中只有一行可以更改日期,并且您的数据库永远不会像这样不一致。

You're really not exploiting the relational nature of databases. The nice way to do it is:

  • Have a table of tasks (with unique ids, without the extra milestone field, without the preformers)
  • Have a table of milestones with two columns: the task id and the special milestone field -- only milestones will appear in this table
  • Have a table with two columns: task id and performer
  • 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

I have read that normalization can reduce DB efficiency, that's why I combine them all.

Where? It's a pretty strange claim.

For the table that contain taskid and performer (the 3rd on your list) Would it be like, if task 143 needs Staff A, B, C. In DB, (row 1| 143 | A) (row 2| 143 | B) (row 3| 143 | C) Don't you still have redundancy?

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:

task_id  completion_date  performer
143      May 31, 2011     A
143      May 31, 2011     B
143      May 31, 2011     C

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:

task_id  completion_date  performer
143      May 31, 2011     A
143      May 12, 2011     B
143      May 31, 2101     C

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文