数据库中实体之间的关系

发布于 2024-10-13 14:00:30 字数 136 浏览 11 评论 0原文

在描述实体之间的关系时,如果表中出现主键,我是否理解正确,假设A在表B中具有确定它是否是一对一,一对多等等?

如果表 B 具有带外键的属性,并且表 B 中的每一行都引用 A 行中的同一个表,那么这是一对多关系,对吗?

提前致谢

When describing relationships between entities have I understood it correct if it the occurrence of a primary key in the table, lets say A has in table B that determines whether it is a one-to-one, one-to-many and so on?

If table B has an attribute with foreign keys, and each row in table B has a reference to the same table in row A, then this is a one-to-many relationship, correct?

Thanks in advance

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

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

发布评论

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

评论(3

若无相欠,怎会相见 2024-10-20 14:00:30

您在问题中混淆了表格和行,因此它试图解释更多一点。

如果表 B 有一个外键列,并且该列中的每一行都有一个外键引用表 A 中一行的主键列,那么这是一个一对一关系< /强>。

但是(这就是您所说的),如果表 B 的行中的多个外键引用另一个表 A 中的一个行,那么这是一个一对多关系,因为有多个 B 引用一个 A。


示例 为

员工分配了一种类型的计算机。

表员工:

ID    Name  Computer
==============
1     Mike   1
2     Tom    3
3     Joe    1
4     Emily  4

表计算机类型:

ID    Name
==============
1     HP
2     Macbook Pro
3     Dell
4     Alienware

那么这是一个一对多关系,告诉我们一种计算机类型可以分配给 >许多员工,即 Joe 和 Mike 使用 HP 计算机。

You're mixing up tables and rows in your question, so it'm trying to explain a little more.

If Table B has a column for foreign keys, and each of the rows in this column has a foreign key that refers to the primary key column of a row in Table A, then this is a one-to-one relationship.

However (and this is what you're stating), if several foreign keys in rows of Table B refer to one row in another Table A, then this is a one-to-many relationship, as there are multiple B's referring to one A.


Example

Employees are assigned a type of computer.

Table Employees:

ID    Name  Computer
==============
1     Mike   1
2     Tom    3
3     Joe    1
4     Emily  4

Table Computer Types:

ID    Name
==============
1     HP
2     Macbook Pro
3     Dell
4     Alienware

Then this is a one-to-many relationship telling us that one computer type can be assigned to many employees, i.e. Joe and Mike are using HP computers.

梦亿 2024-10-20 14:00:30

关系是在特定的“表”之间而不是行之间。表永远不能有重复的主键,但可以有重复的外键。表之间的关系就是您所需要的。一个 Cardriver 可以拥有多辆车,一辆车可以有多个 Cardriver,但只能有一个车主。一辆车只能有一个车牌,一个车牌只能链接到一辆特定的汽车。

有关更多信息。请查看以下链接。那里有详细描述。

http://en.wikipedia.org/wiki/Entity-relationship_model

Relationships are between specific "Tables" not between rows.. A table can never have duplicate primary keys, but can have duplicate foreign keys. The relationship between tables is the thing you need it to be.. One Cardriver can have multiple vehicles and a vehicle can have multiple Cardrivers, but can only have one owner. One car can only have one license plate and one license plate can only be linked to one specific car..

For more information.. Just look at the following link.. it's described in detail there..

http://en.wikipedia.org/wiki/Entity-relationship_model

债姬 2024-10-20 14:00:30

关系数据库模型实体关系建模(ER建模)是两种截然不同的数据建模范例。 ER 建模倾向于将数据模型简化为一些非常简单的概念(例如实体和它们之间的二元关系),而关系数据库模型原则上可以比这更丰富、更强大。当尝试使用 ER 建模术语描述关系数据库概念(这正是您想要做的)时,应牢记这种潜在的不匹配。

在关系数据库中,所有关系都以与所有其他信息相同的方式表示:作为关系内元组内的值(关系或关系变量更常见地称为表)。然而,通常情况下,表中最重要或最明显的关系是那些还引用其他表的关系(“外键”)。这些是 ER 建模通常关注的关系。

对于简单的二元关系,无论是在单个表内还是表之间,请考虑属性 A 和 B 之间关系的规范示例。如果 A 仅是相关表中的候选键,则 A 和 B 之间的有效关系是一对多(或一对零或多)。如果 A B 都是候选键,则关系是一对一(或一对零或一)。

The Relational Database Model and Entity-Relationship Modelling (ER-modelling) are two quite different data modelling paradigms. ER-modelling tends to reduce a data model to a few very simple concepts (e.g. entities and binary relationships between them) whereas the relational database model can in principle be much richer and more powerful than that. This potential mismatch should be kept in mind when attempting to describe relational database concepts using ER-modelling terms, which is what you are trying to do.

In a relational database all relationships are represented in the same way as all other information: as values within tuples within relations (a relation or relation variable is what is more familiarly called a table). However, it's often the case that the most important or obvious relationships within a table are those that also reference other tables ("foreign keys"). Those are the relationships which ER-modelling is usually concerned with.

For simple binary relationships, whether within a single table or between tables, consider the canonical example of a relationship between attributes A and B. If A only is a candidate key in the table(s) in question then the effective relationship between A and B is one to many (or one to zero-or-many). If both A and B are candidate keys then the relationship is one to one (or one to zero-or-one).

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