Algorithm Search⌘K

Modelintro

Entity-relationship model

Also called ER model, entity-relationship diagram, Chen's ER model.

Chen's conceptual model of entities, attributes and relationships with cardinality constraints, and its mapping to relation schemas.

The entity-relationship (ER) model of Chen (1976) describes a database at the conceptual level, as sets of entities, sets of relationships among them, attributes, and constraints on how many relationships an entity may take part in. A design in the ER model is then mapped to relation schemas of the relational model, with keys and foreign keys. The relational model and normalization work on the result of this mapping. This page defines the parts of the model, its instances, the standard mapping, and two facts about what the model can and cannot express.

The machine

Entity sets. An entity set EE is a named set of entities of one kind, such as Employees. It has attributes A1,…,AmA_1, \ldots, A_m, each with a domain, and each entity has one value for each attribute. A key of EE is a set of attributes whose values identify the entity within EE; one key is chosen as the primary key, as for a candidate key of a relation.

  • A composite attribute, such as an address, has parts, such as street and city.
  • A multivalued attribute, such as a set of phone numbers, has a set of values for each entity.
  • A derived attribute, such as an age computed from a birth date, is not stored.

Relationship sets. A relationship set RR of degree nn among entity sets E1,…,EnE_1, \ldots, E_n (not necessarily distinct) is a set of tuples (e1,…,en)(e_1, \ldots, e_n) with ei∈Eie_i \in E_i. Each position is a role, and the role names are needed when an entity set occurs twice, as in a relationship Reports_To between two employees. Under set semantics a combination of entities occurs at most once. A relationship set can have its own descriptive attributes, such as the date since which an employee works in a department.

Cardinality constraints. A constraint (mini,maxi)(\mathit{min}_i, \mathit{max}_i) on role ii of RR says that each entity of EiE_i occurs in role ii of at least mini\mathit{min}_i and at most maxi\mathit{max}_i tuples of RR, with maxi=∞\mathit{max}_i = \infty allowed. The usual special cases:

  • Key constraint (many-to-one): maxi=1\mathit{max}_i = 1. In a binary relationship, each entity of EiE_i is related to at most one entity of the other set.
  • Total participation: mini≥1\mathit{min}_i \ge 1. Each entity of EiE_i takes part in at least one relationship.
  • One-to-one, one-to-many and many-to-many binary relationships: max=1\mathit{max} = 1 on both roles, on one role, or on neither.

Weak entity sets. A weak entity set WW has no key of its own. It is identified through an identifying relationship with an owner entity set OO, in which WW has a key constraint and total participation. A partial key of WW identifies a weak entity among those of one owner, so the key of OO together with the partial key is a key of WW.

Class hierarchies. In the extended ER model, an entity set can have subclasses (ISA), whose entities are also entities of the superclass and inherit its attributes and key. Overlap constraints say whether an entity can be in two subclasses, and covering constraints say whether each entity of the superclass is in some subclass.

Instances. An instance assigns a finite set of entities, with attribute values, to each entity set, and a finite set of tuples to each relationship set. It is legal when the keys identify the entities, each relationship tuple uses entities of the right sets, and all cardinality, weak entity and hierarchy constraints hold.

The mapping to relations. The standard mapping is as follows. Here KEK_E is the primary key of EE.

ER construct relation schema key and constraints
entity set EE EE with the simple attributes of EE, composite ones flattened into their parts KEK_E
many-to-many RR among E1,…,EnE_1, \ldots, E_n R(KE1,…,KEnR(K_{E_1}, \ldots, K_{E_n}, attributes of R)R) KE1⋯KEnK_{E_1} \cdots K_{E_n}; a foreign key from each KEiK_{E_i} to EiE_i
binary RR with a key constraint on E1E_1 as above with key KE1K_{E_1}, or folded into E1E_1 as the columns KE2K_{E_2} and the attributes of RR if folded, the columns are null for entities of E1E_1 in no relationship
weak entity set WW with owner OO W(KOW(K_O, partial key, attributes of W)W) KOK_O with the partial key; a foreign key to OO, with deletion cascading from OO
subclass SS of EE S(KES(K_E, attributes of S)S), or one relation per leaf class with all inherited attributes KEK_E; a foreign key to EE in the first form
multivalued attribute AA of EE E_A(KE,A)E\_A(K_E, A) KEAK_E A; a foreign key to EE

The foreign keys are inclusion dependencies into keys. The keys are functional dependencies of the form K→UK \to U. Each relation of the mapping, with only its key FD, is in BCNF.

Example. This is the running example of Ramakrishnan and Gehrke. The entity sets are Employees(ssn, name, lot) with key ssn and Departments(did, dname, budget) with key did. Works_In is a many-to-many relationship between them with the attribute since, so it becomes Works_In(ssn, did, since) with key (ssn, did) and two foreign keys. Manages gives each department at most one manager, so it is folded into Dept_Mgr(did, dname, budget, ssn, since) with key did, where ssn is null for a department without a manager. Dependents is a weak entity set with partial key pname, owned by Employees through the relationship Policy, so it becomes Dep_Policy(pname, age, cost, ssn) with key (pname, ssn) and a foreign key to Employees with cascading deletes.

What it counts

The model has no running time. What it counts are participations, and they give simple bounds on the sizes of a legal instance. Each tuple of RR has exactly one entity in role ii, so the number of tuples of RR is the sum over the entities of EiE_i of their participations in role ii. A constraint (mini,maxi)(\mathit{min}_i, \mathit{max}_i) on role ii then gives

mini⋅∣Ei∣  ≤  ∣R∣  ≤  maxi⋅∣Ei∣\mathit{min}_i \cdot |E_i| \;\le\; |R| \;\le\; \mathit{max}_i \cdot |E_i|

for each role ii. For example, a binary relationship that is one-to-one with total participation on both sides forces ∣E1∣=∣R∣=∣E2∣|E_1| = |R| = |E_2|.

The mapping gives one relation for each entity set, each weak entity set, each relationship set that is not folded, and each multivalued attribute. Folding a many-to-one relationship into its entity set saves a relation and a join, at the cost of null values for entities that take no part.

Relation to other models

  • Relational model. The mapping above turns an ER design into relation schemas with keys and foreign keys. Some ER constraints have no direct form as keys and foreign keys. Total participation of EE in a many-to-many RR is the inclusion dependency πKE(E)⊆πKE(R)\pi_{K_E}(E) \subseteq \pi_{K_E}(R), whose right side is not a key of RR, so SQL needs a check, an assertion or a trigger for it. A cardinality bound such as max=3\mathit{max} = 3 has no key form either.
  • Normalization. An ER diagram shows the keys of entity sets but not the FDs among their attributes. If Employees has the attributes zip and city with zip →\to city, the relation Employees is not in BCNF, and normalization is still needed after the mapping. A ternary relationship among Course, Teacher and Book in which the teachers and the books of a course are independent has the multivalued dependency course ↠\twoheadrightarrow teacher, and its relation violates 4NF; the better design has two binary relationships.
  • UML and the earlier models. UML class diagrams use the same ideas, with associations and multiplicities in place of relationship sets and cardinality constraints. Chen presented the ER model as a common view of the network, relational and entity set models of the time.

Known results in the model

A ternary relationship is not the join of its binary projections. Let Supplies relate suppliers, parts and projects, with the three tuples (s1,p1,j2)(s_1, p_1, j_2), (s1,p2,j1)(s_1, p_2, j_1) and (s2,p1,j1)(s_2, p_1, j_1). Its projections on supplier and part, part and project, and project and supplier contain s1p1s_1 p_1, p1j1p_1 j_1 and j1s1j_1 s_1, so their join contains (s1,p1,j1)(s_1, p_1, j_1), which is not in Supplies. So replacing a ternary relationship set by three binary ones loses information in general. It is safe exactly when the relationship set satisfies the join dependency ⋈[SP,PJ,JS]\bowtie[SP, PJ, JS].

Cardinality constraints can force empty sets in finite instances. Take one entity set EE and a binary relationship RR on E×EE \times E with the constraint (2,∞)(2, \infty) on role 1 and (0,1)(0, 1) on role 2. By the bounds above, 2∣E∣≤∣R∣≤∣E∣2|E| \le |R| \le |E|, so every finite legal instance has E=∅E = \emptyset. An infinite instance with EE nonempty exists: let EE be the set of finite binary strings and R={(w,w0),(w,w1)}R = \{(w, w0), (w, w1)\}. Each string is first in two tuples, and each string is second in at most one tuple, since the empty string is second in none. So satisfiability over finite instances and over all instances differ. Lenzerini and Nobili (1990) studied this question for ER schemas with cardinality constraints. A designer can apply the bounds of the previous section to the constraints of a schema to find such conflicts.

References

  1. Peter Pin-Shan Chen, The entity-relationship model, toward a unified view of data, ACM Transactions on Database Systems 1(1), 9 to 36 (1976), entity sets, relationship sets, roles and attributes, the ER diagram, and the derivation of relations from the model
  2. Raghu Ramakrishnan and Johannes Gehrke, Database Management Systems, third edition, McGraw-Hill (2003), Chapter 2 (the ER model, key and participation constraints, weak entities, class hierarchies) and Section 3.5 (from ER diagrams to relational tables)
  3. Abraham Silberschatz, Henry F. Korth and S. Sudarshan, Database System Concepts, seventh edition, McGraw-Hill (2020), Chapter 6 (database design using the E-R model), including Section 6.7 on reducing E-R diagrams to relational schemas
  4. Maurizio Lenzerini and Paolo Nobili, On the satisfiability of dependency constraints in entity-relationship schemata, Information Systems 15(4), 453 to 461 (1990), the satisfiability of cardinality constraints in ER schemas and the case of finite instances

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/RN0VS0/text.yaml