代码之家  ›  专栏  ›  技术社区  ›  Tassadaque

Relational database Design- Relationship problem

  •  1
  • Tassadaque  · 技术社区  · 15 年前

    对于没有组的简单备忘录,我将使用“memomasters”和“memodetail”,memodetail将employeeID作为外键。我如何在这个结构中嵌入组

    当做

    3 回复  |  直到 11 年前
        1
  •  1
  •   PerformanceDBA    14 年前

    只要你把它作为一个关系建模任务来处理,我看不出它的复杂性。假设你想要一个纯粹的关系解决方案,试试这个 Memo Data Model . If you are unfamiliar with the Standard for modelling Relational databases, the IDEF1X Notation 可能会有帮助。

    1. It uses an ordinary Supertype-Subtype Structure.

      • In this case it is Exclusive: the MemoAddress ie 任何一个 以及雇员地址 群组地址。

      • Exclusive Subtypes need a Discriminator in the Supertype: I have used a boolean IsEmployee , a CHAR code or similar is also common.

    2. This is pure 5NF; no Update Anomalies; full Declarative Referential Integrity.

    3. Ack is in the right place (I've used a DateTime, but boolean is fine as well).

    4. 不过,如果您不习惯使用父类型子类型结构,填充该结构的投影可能看起来很难看;只需询问您是否需要帮助。

    5. 不要以不同的方式对待“一个员工的简单备忘录”,否则会遇到问题、重复的代码等。

    6. A separate issue is, you may need the EmployeeId Employee 写的 这个 Memo 这是另一回事,为此你需要一个FK 员工 在里面 备忘录 .

        2
  •  0
  •   Unreason    15 年前

    In this structure you could not.

    这是一个 many to many relationship, model it as such.

    编辑(查看方案): The above requirements are not enough to determine the 'exact solution'

    At the risk of overly simplifying, you should:

    1) check if you can stick the new information into any existing tables/entities
    2) if not, then check if adding attributes/columns to any of the existing tables/entties
    3) if not, then add a new table

    The decisions are never clearly cut and you 应该 考虑几个场景及其后果。您还应该定期检查您的模型,因为它可以寻找机会来规范化它,因为它将极大地影响系统的整体功能。

    例如,正如您所说的那样,您已经有了一个多对多的分组表,现在的主要问题是是否可以重用该表或创建一个新的表。

    这取决于此表中的其他属性。也许对于您的业务模型/用例来说,它是有意义的,也许它不是。

    也许您需要将一个名为“memorecipients”的表建模,该表将存储有关收件人的信息(传递、确认等)。然后你应该问自己,你是否需要这些状态的时间,等等……

    只有你才能确定什么是你的问题空间的正确设计决策。

        3
  •  0
  •   Community CDub    8 年前

    似乎你需要继承权来实现你所描述的。考虑下图:

    在这个图中,您创建了一个父表(我称之为海报),Employee和Group表是子表。您必须给Employee表和Group表相同的主键,也就是说,从Group到Poster和Employee到Poster有一对一的链接。

    这样,备忘录的海报栏就指向了超级班级。您可以在海报、团队和员工之间执行连接,以确定您是指某个员工还是指某个团队。

    我在图表中遗漏了员工和团队之间的关系,正如您所说,您已经拥有了这一点。

    Note that this is just an illustration of what is possible, you solution may vary.

    在这个图中,您创建了一个父表(我称之为海报),Employee和Group表是子表。您必须给Employee表和Group表提供相同的主键,也就是说,从Group到Poster和Employee到Poster都有一对一的链接。

    这样,备忘录的海报栏就指向了超级班级。您可以在海报、组和员工之间执行联接,以确定您是指某个员工还是指某个组。

    我在图表中遗漏了员工和团队之间的关系,正如您所说的那样。

    Note that this is just an illustration of what is possible, you solution may vary.