实体关系模型和关系模型之间有什么区别?

时间:2022-10-05 11:57:56

I was only able to find the following two differences:

我只能找到以下两个不同之处:

  1. The relationships in an E-R model are explicitly defined, while they are implicit in a relational model.
  2. E-R模型中的关系是明确定义的,而它们隐含在关系模型中。
  3. Relational models require an intermediate table (often called a "junction table") to hold two foreign keys that implement the many-to-many relationship.
  4. 关系模型需要一个中间表(通常称为“联结表”)来保存两个实现多对多关系的外键。

And why do we use the relational model, when we have an E-R diagram ?

当我们有E-R图时,为什么我们使用关系模型?

2 个解决方案

#1


12  

You have it backwards.

你倒退了。

  1. The relationships in an E-R model are explicitly defined, while they are implicit in a relational model.
  2. E-R模型中的关系是明确定义的,而它们隐含在关系模型中。

No. Each Relational Model (RM) database base table and query result represents an application relationship. Entity-Relationship Modeling (E-RM) schemas are just a way of organizing (but under-using and under-specifying) (but with misunderstanding) relational tables and constraints.

不可以。每个关系模型(RM)数据库基表和查询结果表示应用程序关系。实体 - 关系建模(E-RM)模式只是组织(但使用不足和指定不足)(但有误解)关系表和约束的一种方式。

  1. Relational models require an intermediate table (often called a "junction table") to hold two foreign keys that implement the many-to-many relationship.
  2. 关系模型需要一个中间表(通常称为“联结表”)来保存两个实现多对多关系的外键。

No. It is Object-Relational Mapping (ORM) approaches that obscure their underlying straightforward relational application relationships, tables and constraints. The notion of "junction table" arose from ORM misunderstandings of confused presentations of the E-RM which itself misunderstands the RM.

不是。对象关系映射(ORM)方法模糊了它们潜在的直接关系应用程序关系,表和约束。 “交联表”的概念源于ORM对E-RM的混乱陈述的误解,E-RM本身误解了RM。

As C J Date put it An Introduction to Database Systems, 8th ed:

正如C J Date所说,数据库系统简介,第8版:

a charitable reading of [Chen's original paper] would suggest that the E/R model is indeed a data model, but one that is essentially just a thin layer on top of the basic relational model [p 426]

[Chen的原始论文]的慈善阅读将表明E / R模型确实是一个数据模型,但基本关系模型之上基本上只是一个薄层[p 426]

It is a sad comment on the state of the IT field that simple solutions are popular even when they are too simple. [p 427]

对于IT领域的状态,这是一个悲伤的评论,即使简单的解决方案过于简单,它们也很受欢迎。 [第427页]

The Relational Model

关系模型

Every relational table represents an application relationship.

每个关系表都代表一个应用程序关系。

-- employee EID has name NAME and ...
E(EID,NAME,...)

The mathematical term for such a thing, and also for a mathematical ordered-tuple set representing one, is a "relation". Hence the "Relational Model" (and "Entity-Relationship Modeling"). In mathematics relations are frequently described by parameterized statement templates for which one mathematical term is "characteristic predicate". The parameters of the predicate are columns of the table. In the RM a DBA gives a predicate for each base table and users put the rows that make a true statement from column values and the predicate into the table and leave the rows that make a false statement out.

这种事物的数学术语,以及代表一个的数学有序元组集,是一种“关系”。因此,“关系模型”(和“实体 - 关系建模”)。在数学中,关系经常由参数化语句模板描述,其中一个数学术语是“特征谓词”。谓词的参数是表的列。在RM中,DBA为每个基表提供谓词,并且用户将从列值和谓词生成真实语句的行放入表中,并保留用于生成false语句的行。

/* now also employee 717 has name 'Smith' and ...
    AND employee 202 has name 'Doodle' and ...
*/
INSERT INTO E VALUES (EID,NAME,...)
    (717,'Smith',...),(202,'Doodle',...)

A query expression also has a predicate built from the relation operators and logic operators (in conditions) in it. Its value also holds the rows that make its predicate true and leaves out the ones that make it false.

查询表达式还具有从关系运算符和逻辑运算符(在条件中)构建的谓词。它的值还包含使其谓词成立的行,并省略使其成为假的行。

/* rows where
   FOR SOME E.*, M.*,
        EID = E.EID AND ... AND MID = M.MID
   AND employee E.EID has name E.NAME and ...
   AND manager M.MID has 
   AND E.DEPT = M.DEPT AND E.NAME = 'Smith'
/*
SELECT E.*, M.MID
FROM E JOIN M ON E.DEPT = M.DEPT
WHERE E.NAME = 'Smith'

Present rows of tables making true statements and absent rows making false statements is how we record about the application situation in the database and how we interpret what the database is saying about the application situation. One can't use or interpret the database without having and understanding the predicates ie application relationships.

呈现真实语句和缺少行生成错误语句的表行是我们如何记录数据库中的应用程序情况以及我们如何解释数据库对应用程序情况的说法。在没有和理解谓词即应用程序关系的情况下,不能使用或解释数据库。

Entity-Relationship Modeling

实体关系建模

E-RM (which does not really understand the RM) is essentially a(n unnecessary, restricted and restrictive) diagramming notation for describing (some parts of) (limited forms of) relational databases. Originally there were "entity (class)" icons/relations where the candidate key (CK) values were 1:1 with application entities plus other columns ("properties" of the "entity") and there were "relationship (class)" icons/tables which had foreign keys (FKs) to entity tables representing application relationships on multiple entities plus other things ("properties" of the "association"). An application relationship was represented by an icon with lines to the various entity icons that participated in it. (Ie the lines represented FKs. Which are not relationships but statements about constraints on tables.)

E-RM(它并不真正理解RM)本质上是用于描述(某些部分)(有限形式)关系数据库的(不必要的,限制性的和限制性的)图表符号。最初有“实体(类)”图标/关系,其中候选键(CK)值为1:1,应用程序实体加上其他列(“实体”的“属性”),并且存在“关系(类)”图标/表具有外键(FK)到实体表,表示多个实体上的应用程序关系以及其他内容(“关联”的“属性”)。应用程序关系由一个图标表示,该图标带有指向参与其中的各种实体图标的行。 (即行代表FK。这不是关系,而是关于表的约束的陈述。)

E-RM doesn't understand the relational model. It makes a pointless and misleading distinction between application entities and relationships. After all, every superkey (unique column set) of every base table or query result is in 1:1 correspondence with some application entity, not just the ones that have entity tables. Eg people can be associated by being married; but each such association is 1:1 with an entity called a marriage. This leads to inadequate normalization and constraints, hence redundancy and loss of integrity. Or when those steps are adequately done it leads to the E-R diagram not actually describing the application, which is actually described by the relational database predicates, tables and constraints. Then the E-R diagram is both vague, redundant and wrong.

E-RM不了解关系模型。它在应用程序实体和关系之间做出了毫无意义和误导性的区分。毕竟,每个基表或查询结果的每个超级密钥(唯一列集)与某个应用程序实体1:1对应,而不仅仅是具有实体表的应用程序实体。例如,人们可以通过结婚来结合;但每个这样的关联是1:1,有一个叫做婚姻的实体。这导致标准化和约束不充分,因此冗余和完整性丧失。或者当这些步骤充分完成时,它会导致E-R图实际上没有描述应用程序,这实际上是由关系数据库谓词,表和约束描述的。然后E-R图表既模糊,冗余又错误。

Shorthand E-RM and ORMs

速记E-RM和ORM

A lot of presentations and products claiming to be E-RM warp the E-RM, let alone the RM. They use the word "relationship" to mean a FK constraint. This arises as follows. When an E-RM relationship is binary it is a symbol with two lines to its FKs. So those three things can be replaced by one line between FKs. This kind of line represents that particular binary relationship and its FKs but now the E-R relationship is not explicit in the diagram although the E-R relationship is explicit in the longhand version and it is reflected by a table in what the diagrams are pictures of, namely the relational database they are describing. This gets called a "junction table". And people talk about that line/table being/representing "an X:Y relationship" between entities and/or associations without actually ever noticing that it's a particular application relationship. And there can be many such application relationships between the same two entities and/or associations.

许多声称是E-RM的演示和产品都会使E-RM变形,更不用说RM了。他们使用“关系”一词来表示FK约束。这产生如下。当E-RM关系是二进制时,它是一个符号,其FK为两行。所以这三件事可以用FK之间的一条线代替。这种线表示特定的二元关系及其FK,但现在ER关系在图中并不明确,尽管ER关系在纵向版本中是显式的,并且它由图表中的图表反映出来,即他们正在描述的关系数据库。这被称为“联结表”。并且人们谈论实体和/或关联之间/表示“X:Y关系”的那条线/表,而实际上并没有注意到它是特定的应用关系。并且在相同的两个实体和/或关联之间可以存在许多这样的应用关系。

ORMs do this too but also replace n-ary associations by just their FKs so that the associated application relationship and table are further obscured. Active Records goes even further by defining several shorthand relationships and their tables at once, equivalent to a chain of FK lines and association icons in the longhand E-RM diagram. This is exacerbated by many modeling techniques, including versions of E-RM and ORMs, also thinking that application relationships can only be binary. Again, this arose historically from lack of understanding of the RM.

ORM也这样做,但也只用它们的FK替换n元关联,以便进一步模糊相关的应用程序关系和表。 Active Records通过一次定义几个简写关系及其表来进一步发展,相当于简写E-RM图中的一系列FK线和关联图标。许多建模技术加剧了这一点,包括E-RM和ORM的版本,也认为应用程序关系只能是二进制的。同样,这在历史上源于对RM的缺乏了解。

#2


1  

They are two different things per se. A relational model represents information as tuples, directly mapped to a relational schema. The guidelines stem from relational algebra.

它们本身就是两个不同的东西。关系模型将信息表示为元组,直接映射到关系模式。该指南源于关系代数。

Meanwhile, an ER diagram models the relationships between the users and their underlying data in a system using entities. An ER diagram can be mapped to a relational model, and finally to a working schema.

同时,ER图使用实体模拟用户及其基础数据之间的关系。 ER图可以映射到关系模型,最后映射到工作模式。

#1


12  

You have it backwards.

你倒退了。

  1. The relationships in an E-R model are explicitly defined, while they are implicit in a relational model.
  2. E-R模型中的关系是明确定义的,而它们隐含在关系模型中。

No. Each Relational Model (RM) database base table and query result represents an application relationship. Entity-Relationship Modeling (E-RM) schemas are just a way of organizing (but under-using and under-specifying) (but with misunderstanding) relational tables and constraints.

不可以。每个关系模型(RM)数据库基表和查询结果表示应用程序关系。实体 - 关系建模(E-RM)模式只是组织(但使用不足和指定不足)(但有误解)关系表和约束的一种方式。

  1. Relational models require an intermediate table (often called a "junction table") to hold two foreign keys that implement the many-to-many relationship.
  2. 关系模型需要一个中间表(通常称为“联结表”)来保存两个实现多对多关系的外键。

No. It is Object-Relational Mapping (ORM) approaches that obscure their underlying straightforward relational application relationships, tables and constraints. The notion of "junction table" arose from ORM misunderstandings of confused presentations of the E-RM which itself misunderstands the RM.

不是。对象关系映射(ORM)方法模糊了它们潜在的直接关系应用程序关系,表和约束。 “交联表”的概念源于ORM对E-RM的混乱陈述的误解,E-RM本身误解了RM。

As C J Date put it An Introduction to Database Systems, 8th ed:

正如C J Date所说,数据库系统简介,第8版:

a charitable reading of [Chen's original paper] would suggest that the E/R model is indeed a data model, but one that is essentially just a thin layer on top of the basic relational model [p 426]

[Chen的原始论文]的慈善阅读将表明E / R模型确实是一个数据模型,但基本关系模型之上基本上只是一个薄层[p 426]

It is a sad comment on the state of the IT field that simple solutions are popular even when they are too simple. [p 427]

对于IT领域的状态,这是一个悲伤的评论,即使简单的解决方案过于简单,它们也很受欢迎。 [第427页]

The Relational Model

关系模型

Every relational table represents an application relationship.

每个关系表都代表一个应用程序关系。

-- employee EID has name NAME and ...
E(EID,NAME,...)

The mathematical term for such a thing, and also for a mathematical ordered-tuple set representing one, is a "relation". Hence the "Relational Model" (and "Entity-Relationship Modeling"). In mathematics relations are frequently described by parameterized statement templates for which one mathematical term is "characteristic predicate". The parameters of the predicate are columns of the table. In the RM a DBA gives a predicate for each base table and users put the rows that make a true statement from column values and the predicate into the table and leave the rows that make a false statement out.

这种事物的数学术语,以及代表一个的数学有序元组集,是一种“关系”。因此,“关系模型”(和“实体 - 关系建模”)。在数学中,关系经常由参数化语句模板描述,其中一个数学术语是“特征谓词”。谓词的参数是表的列。在RM中,DBA为每个基表提供谓词,并且用户将从列值和谓词生成真实语句的行放入表中,并保留用于生成false语句的行。

/* now also employee 717 has name 'Smith' and ...
    AND employee 202 has name 'Doodle' and ...
*/
INSERT INTO E VALUES (EID,NAME,...)
    (717,'Smith',...),(202,'Doodle',...)

A query expression also has a predicate built from the relation operators and logic operators (in conditions) in it. Its value also holds the rows that make its predicate true and leaves out the ones that make it false.

查询表达式还具有从关系运算符和逻辑运算符(在条件中)构建的谓词。它的值还包含使其谓词成立的行,并省略使其成为假的行。

/* rows where
   FOR SOME E.*, M.*,
        EID = E.EID AND ... AND MID = M.MID
   AND employee E.EID has name E.NAME and ...
   AND manager M.MID has 
   AND E.DEPT = M.DEPT AND E.NAME = 'Smith'
/*
SELECT E.*, M.MID
FROM E JOIN M ON E.DEPT = M.DEPT
WHERE E.NAME = 'Smith'

Present rows of tables making true statements and absent rows making false statements is how we record about the application situation in the database and how we interpret what the database is saying about the application situation. One can't use or interpret the database without having and understanding the predicates ie application relationships.

呈现真实语句和缺少行生成错误语句的表行是我们如何记录数据库中的应用程序情况以及我们如何解释数据库对应用程序情况的说法。在没有和理解谓词即应用程序关系的情况下,不能使用或解释数据库。

Entity-Relationship Modeling

实体关系建模

E-RM (which does not really understand the RM) is essentially a(n unnecessary, restricted and restrictive) diagramming notation for describing (some parts of) (limited forms of) relational databases. Originally there were "entity (class)" icons/relations where the candidate key (CK) values were 1:1 with application entities plus other columns ("properties" of the "entity") and there were "relationship (class)" icons/tables which had foreign keys (FKs) to entity tables representing application relationships on multiple entities plus other things ("properties" of the "association"). An application relationship was represented by an icon with lines to the various entity icons that participated in it. (Ie the lines represented FKs. Which are not relationships but statements about constraints on tables.)

E-RM(它并不真正理解RM)本质上是用于描述(某些部分)(有限形式)关系数据库的(不必要的,限制性的和限制性的)图表符号。最初有“实体(类)”图标/关系,其中候选键(CK)值为1:1,应用程序实体加上其他列(“实体”的“属性”),并且存在“关系(类)”图标/表具有外键(FK)到实体表,表示多个实体上的应用程序关系以及其他内容(“关联”的“属性”)。应用程序关系由一个图标表示,该图标带有指向参与其中的各种实体图标的行。 (即行代表FK。这不是关系,而是关于表的约束的陈述。)

E-RM doesn't understand the relational model. It makes a pointless and misleading distinction between application entities and relationships. After all, every superkey (unique column set) of every base table or query result is in 1:1 correspondence with some application entity, not just the ones that have entity tables. Eg people can be associated by being married; but each such association is 1:1 with an entity called a marriage. This leads to inadequate normalization and constraints, hence redundancy and loss of integrity. Or when those steps are adequately done it leads to the E-R diagram not actually describing the application, which is actually described by the relational database predicates, tables and constraints. Then the E-R diagram is both vague, redundant and wrong.

E-RM不了解关系模型。它在应用程序实体和关系之间做出了毫无意义和误导性的区分。毕竟,每个基表或查询结果的每个超级密钥(唯一列集)与某个应用程序实体1:1对应,而不仅仅是具有实体表的应用程序实体。例如,人们可以通过结婚来结合;但每个这样的关联是1:1,有一个叫做婚姻的实体。这导致标准化和约束不充分,因此冗余和完整性丧失。或者当这些步骤充分完成时,它会导致E-R图实际上没有描述应用程序,这实际上是由关系数据库谓词,表和约束描述的。然后E-R图表既模糊,冗余又错误。

Shorthand E-RM and ORMs

速记E-RM和ORM

A lot of presentations and products claiming to be E-RM warp the E-RM, let alone the RM. They use the word "relationship" to mean a FK constraint. This arises as follows. When an E-RM relationship is binary it is a symbol with two lines to its FKs. So those three things can be replaced by one line between FKs. This kind of line represents that particular binary relationship and its FKs but now the E-R relationship is not explicit in the diagram although the E-R relationship is explicit in the longhand version and it is reflected by a table in what the diagrams are pictures of, namely the relational database they are describing. This gets called a "junction table". And people talk about that line/table being/representing "an X:Y relationship" between entities and/or associations without actually ever noticing that it's a particular application relationship. And there can be many such application relationships between the same two entities and/or associations.

许多声称是E-RM的演示和产品都会使E-RM变形,更不用说RM了。他们使用“关系”一词来表示FK约束。这产生如下。当E-RM关系是二进制时,它是一个符号,其FK为两行。所以这三件事可以用FK之间的一条线代替。这种线表示特定的二元关系及其FK,但现在ER关系在图中并不明确,尽管ER关系在纵向版本中是显式的,并且它由图表中的图表反映出来,即他们正在描述的关系数据库。这被称为“联结表”。并且人们谈论实体和/或关联之间/表示“X:Y关系”的那条线/表,而实际上并没有注意到它是特定的应用关系。并且在相同的两个实体和/或关联之间可以存在许多这样的应用关系。

ORMs do this too but also replace n-ary associations by just their FKs so that the associated application relationship and table are further obscured. Active Records goes even further by defining several shorthand relationships and their tables at once, equivalent to a chain of FK lines and association icons in the longhand E-RM diagram. This is exacerbated by many modeling techniques, including versions of E-RM and ORMs, also thinking that application relationships can only be binary. Again, this arose historically from lack of understanding of the RM.

ORM也这样做,但也只用它们的FK替换n元关联,以便进一步模糊相关的应用程序关系和表。 Active Records通过一次定义几个简写关系及其表来进一步发展,相当于简写E-RM图中的一系列FK线和关联图标。许多建模技术加剧了这一点,包括E-RM和ORM的版本,也认为应用程序关系只能是二进制的。同样,这在历史上源于对RM的缺乏了解。

#2


1  

They are two different things per se. A relational model represents information as tuples, directly mapped to a relational schema. The guidelines stem from relational algebra.

它们本身就是两个不同的东西。关系模型将信息表示为元组,直接映射到关系模式。该指南源于关系代数。

Meanwhile, an ER diagram models the relationships between the users and their underlying data in a system using entities. An ER diagram can be mapped to a relational model, and finally to a working schema.

同时,ER图使用实体模拟用户及其基础数据之间的关系。 ER图可以映射到关系模型,最后映射到工作模式。