直观又调皮的ER-Model
ER Model Basics
我们知道ER Model其实是 “Entity Relational Model”的简称,其中:
- Entity(Gegenstände): Real-world object distinguishable from other objects.
- An entity is described in DB using a set of attributes.
- Entity Set: A collection of similar entities.
- All entities in an entity set have the same set of attributes.
- Each entity set has a key(Schlüssel) - minimal set of attributes whose value uniquely identify an entity.
- There could be more than one candidate key; the one designated is the primary key.
- Each attribute has a domain - set of permitted values.
- Relationship(Beziehungen ): association among two or more entities
- Relationship set: collection of similar relationships
- An n-ary relationship set R relates n entity sets
- Entity sets: $ E_1…E_n $
- Relationship set: $R = \lbrace (e_1, e_2,…,e_n) | e_1 \in E_1, e_2 \in E_2,…, e_n \in E_n \rbrace $
- Same entity set could participate in different relationship sets.
- A relationship can also have descriptive attributes.
- Record information about the relationship, rather than any participating entities.
- A realationship can only be identified by the participating entities.
- An n-ary relationship set R relates n entity sets
Charakterisierung von Beziehungstypen
这里作为上面的一些补充,除了Beziehungen的比较形式化的定义$R \in E_1 x E_2 x … x E_n$外,对于这些关系还有一些细节需要讨论。
Funktionalitäten der Beziehungen
-
1:1-Beziehung, falls jede Entity $e_1$, aus $E_1$ höchstens ein Eintity $e_2$ aus $E_2$ zugeordnet ist und umgekehrt jedem Entity $e_2$ aus $E_2$ maximal ein Entity $e_1$ aus $E_1$ zugeordnet ist. 当然两个entities中也可以是没有关系的就是了。
-
1:N-Beziehung, falls jede Entity $e_1$ aus $E_1$ beliebig viele (also mehrere oder auch gar keine) Entities aus $E_2$ zugeordnet sein können, aber jedes Entity $e_2$ aus der aus der Menge $E_2$ mit maximal einem Entity aus $E_1$ in Beziehung stehen kann.
-
N:1-Beziehung, falls analoges zu obigem gilt.
-
N:M-Beziehung, wenn keinerlei Restriktionen gelten müssen, d.h. jedes Entity aus $E_1$ mit beliebig vielen Entities aus $E_2$ in Beziehung stehen kann und umgekehrt jedes Entity aus $E_2$ mit beliebig vielen Entities aus $E_1$ assoziiert werden darf.
这些从下面的图中其实也很好去理解:
Type of Relationships
Generalisierung
这个概念更可以理解为是一种「抽象」,就像是java中的父类子类这种关系的感觉,可以通过一种is-a关系来展现这种「抽象」行为。
- Overlap constraint
- Determine whether two sublasses are allowed to contain the same entity.
- Covering constraint
- determine whether the entities in the subclasses collectively include all entities in the superclass.
Reasons for using is-a:
- To add descriptive attributes specific to a subclass
- To identify entites that participate in a relationship
Aggregation
这其实是有一些困惑我的一个概念,因为在书中和我上网查到的资料有些偏差,先看书中是怎么描述的:
“…, werden bei der Aggregation unterschiedliche Entitytypen, die in ihrer Gesamtheit einen strukturierten Objekttypen bilden, einander zugeordnet. In dieser Hinsicht kann man die Aggregation als einen besonderen Beziehungstyp deuten, der einem übergeordneten Entitiestyp mehrere untergeordnete Entitytypen zuordnet. Diese Beziehung wird als Teil-von(part-of) bezeichnet, um zu betonen, dass die untergeordneten Entities Teile (also Komponente) der übergeordneten (zusammengesetzten) Entities sind."1
然后找到的其他资料是这么描述的:
- sometimes we have to model a relaitonship between a collection of entities and relationships.
- Aggregation allows us to treat a relationship set as an entity set.
- we use dashed box around the relationship set to denote aggregation.
-
[Kemper, Alfons and Eickler, André, Datenbanksysteme: Eine Einführung, 7.,ISBN:9783486590180] ↩︎