何时使用关联实体? [英] When to use Associative entities?

查看:93
本文介绍了何时使用关联实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有两个实体,分别称为Employee和Campaign。一名员工可以从事许多活动。一个活动可以有很多员工。我已经知道这是一个多对多的关系。

Suppose there are two entities called Employee and Campaign. One employee can work on many campaigns. And one campaign can have many employees. I already know this is a many to many relationship.

当绘制ER图(用Chen表示)时,该关系用菱形表示。但是关联实体有一个单独的符号,表示两个实体之间的多对多关系。

And when drawing the ER diagram (in Chen notation), the relationship is symbolized by a diamond shape. But there is a separate symbol for associative entities, which symbolizes a many to many relationship between two entities.

1)所以我应该使用菱形形状还是关联实体形状(正方形内的菱形)在用Chen的符号在er图中绘制多对多关系时?

2)它们两者是指同一事物还是不同事物?

3)如果它们是两件分开的事情,我该如何确定何时使用哪个?

1) So should I use the diamond shape or the associative entity shape (diamond inside a square) when drawing many to many relationships in er diagram in Chen's notation?
2) Do they both mean the same thing or different things?
3) If they are two separate things, how can I identify when to use which?

推荐答案

在需要建立关系时会使用关联实体

Associative entities are used when you need a relationship to be involved in a relationship.

例如:

对于学生课程,我们将仅使用钻石。但是,如果我们想将注册教师相关联,我们可以将注册进入关联实体。

For a normal many-to-many relationship between Student and Course, we would use just a diamond. However, if we want to associate Enrollment with Teacher, we can turn Enrollment into an associative entity.

基本上,我们的数据库如下所示:

Phyiscally, our database looks like this:

制作注册三元关系,其中 Teacher 是可选角色,其含义大致相同(除非将其规范化) ,并且角色可以为空)。

Making Enrollment a ternary relationship in which the Teacher is an optional role would have much the same meaning (except it would be denormalized, having a nullable role).

这篇关于何时使用关联实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆