实体关系图

发布于 2024-08-29 12:48:00 字数 384 浏览 6 评论 0原文

我想加深对 ER 图中基数约束的理解。

我有两个实体:

  1. User
  2. Location

但是,我希望这两个实体之间的关系是多对多(一个用户可以位于多个位置,一个位置可以位于多个位置)有很多用户)。

为此,我需要引入一个关联类UserLocation

我现在有 3 个实体,这样说是否正确?

如果我要绘制上面的 ER 图,我会绘制 UserLocation 实体吗?基数会像这样吗?

User 1 ------ * User Location *  ------ 1 Location

I'd like to improve my understanding of cardinality constraints in ER diagrams.

I have two entities:

  1. User
  2. Location

But, I want the relationship between these two entities to be many-to-many (a user can be in many locations and a location can have many users).

To do this I need to introduce an association class UserLocation.

Is it correct to say I now have 3 entities?

If I were to draw an ER diagam of the above, would I draw in the UserLocation entity, and would the cardinality look like this?

User 1 ------ * User Location *  ------ 1 Location

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

无妨# 2024-09-05 12:48:00

您不需要第三个实体。

在实体世界中,其建模如下:

  • 实体用户有一个位置列表。
  • 实体位置有一个用户列表。

在关系世界中,建模如下:

  • 一个表 USER,带有主键 USER_ID
  • 一个表 LOCATION,带有主键 LOCATION_ID
  • 一个表 USER_LOCATION,带有两个外键,每个外键对应上述表。

我相信在关系图中“中介”是不可见的。所以,我认为你需要这样的东西:

用户 * ------- * 位置

You do not need a third entity.

In the Entity world, this is modeled like this:

  • The entity User has a list of Locations.
  • The entity Location has a list of Users.

In the Relational world, this is modeled like this:

  • A table USER, with primary key USER_ID
  • A table LOCATION, with primary key LOCATION_ID
  • A table USER_LOCATION, with two foreign keys, one to each of the above tables.

I believe that in the Relational diagram the "intermediary" is not visible. So, I think you would need something like this:

User * ------- * Location

贪了杯 2024-09-05 12:48:00

这完全取决于您正在执行的实体映射的类型和级别。

您可以将关系表示为

实体 1 <>实体2

例如用“乌鸦脚”来表示许多关系。

当规范化映射时,您将打破与中间表的多对多关系,这通常包含多个表的主键

Entity 1 > Entity 1实体3<实体 2

其中实体 3(您的中间表)将保存两个表的 PK,有时还保存任何其他数据,例如唯一 ID 等。

It all depends on the type and level of entitiy mapping you are doing.

You can express the relationship as it is

Entity 1 <> Entity 2

Such as using the 'Crows Feet' to represent the many relationship.

When normalising the map you would break up the many to many relationships with an intermediate table, this would normally contain the primary keys of both of the many tables

Entity 1 > Entity 3 < Entity 2

Where Entity 3 (your intermedite table) would hold PK's for both tables, and ocassionally any other data, such as a unique ID etc.

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