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 is a named set of entities of one kind, such as Employees. It has attributes , each with a domain, and each entity has one value for each attribute. A key of is a set of attributes whose values identify the entity within ; 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 of degree among entity sets (not necessarily distinct) is a set of tuples with . 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 on role of says that each entity of occurs in role of at least and at most tuples of , with allowed. The usual special cases:
- Key constraint (many-to-one): . In a binary relationship, each entity of is related to at most one entity of the other set.
- Total participation: . Each entity of takes part in at least one relationship.
- One-to-one, one-to-many and many-to-many binary relationships: on both roles, on one role, or on neither.
Weak entity sets. A weak entity set has no key of its own. It is identified through an identifying relationship with an owner entity set , in which has a key constraint and total participation. A partial key of identifies a weak entity among those of one owner, so the key of together with the partial key is a key of .
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 is the primary key of .
| ER construct | relation schema | key and constraints |
|---|---|---|
| entity set | with the simple attributes of , composite ones flattened into their parts | |
| many-to-many among | , attributes of | ; a foreign key from each to |
| binary with a key constraint on | as above with key , or folded into as the columns and the attributes of | if folded, the columns are null for entities of in no relationship |
| weak entity set with owner | , partial key, attributes of | with the partial key; a foreign key to , with deletion cascading from |
| subclass of | , attributes of , or one relation per leaf class with all inherited attributes | ; a foreign key to in the first form |
| multivalued attribute of | ; a foreign key to |
The foreign keys are inclusion dependencies into keys. The keys are functional dependencies of the form . 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 has exactly one entity in role , so the number of tuples of is the sum over the entities of of their participations in role . A constraint on role then gives
for each role . For example, a binary relationship that is one-to-one with total participation on both sides forces .
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 in a many-to-many is the inclusion dependency , whose right side is not a key of , so SQL needs a check, an assertion or a trigger for it. A cardinality bound such as 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 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 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 , and . Its projections on supplier and part, part and project, and project and supplier contain , and , so their join contains , 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 .
Cardinality constraints can force empty sets in finite instances. Take one entity set and a binary relationship on with the constraint on role 1 and on role 2. By the bounds above, , so every finite legal instance has . An infinite instance with nonempty exists: let be the set of finite binary strings and . 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
- 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
- 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)
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag RN0VS0 Edit this page History Report an error Markdown