Chapter 2: Entity - Relationship Model
Chapter 2: Entity - Relationship Model
Whats the use of the E-R model? Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an E-R Database Schema Reduction of an E-R Schema to Tables
2.1
E-R Diagrams
Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes. Underline indicates primary key attributes (will study later)
Database System Concepts 2.2 Silberschatz, Korth and Sudarshan
Attributes
An entity is represented by a set of attributes, that is descriptive
properties possessed by all members of an entity set. Example: customer = (customer-id, customer-name, customer-street, customer-city) loan = (loan-number, amount) Domain the set of permitted values for each attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes
E.g.
multivalued attribute: phone-numbers be computed from other attributes age, given date of birth
Derived attributes
Can E.g.
2.3
Entity Sets
A database can be modeled as:
2.4
2.5
E-R Diagram With Composite, Multivalued, and Derived Attributes Attributestry to avoid them
2.6
Composite Attributes
2.7
Roles
Entity sets of a relationship need not be distinct
The labels manager and worker are called roles; they specify how
diamonds to rectangles.
Role labels are optional, and are used to clarify semantics of the
relationship
2.8
Mapping Cardinalities
Express the number of entities to which another entity can be
one of the following types: One to one One to many Many to one Many to many
2.9
Mapping Cardinalities
One to one
One to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Database System Concepts 2.10 Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Many to one
Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Database System Concepts 2.11 Silberschatz, Korth and Sudarshan
OneOne-ToTo-Many Relationship
In the one-to-many relationship a loan is associated with at most
one customer via borrower, a customer is associated with several (including 0) loans via borrower
2.12
ManyMany-ToTo-One Relationships
Example of many-to-one relationships: a loan is associated with
several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
2.13
Cardinality Constraints
We express cardinality constraints by drawing either a directed
line (), signifying one, or an undirected line (), signifying many, between the relationship set and the entity set.
Example of One-to-one relationship:
2.14
ManyMany-ToTo-Many Relationship
2.15
2.16
Keys
A super key of an entity set is a set of one or more attributes
2.17
set.
Relationship sets that involve two entity sets are binary (or degree
2.18
2.19
1. each A entity is associated with a unique entity from B and C or 2. each pair of entities from (A, B) is associated with a unique C entity,
and each pair (A, C) is associated with a unique B
Each alternative has been used in different formalisms To avoid confusion we outlaw more than one arrow
2.20
10
represented using binary relationships E.g. A ternary relationship parents, relating a child to his/her father and
mother, is best replaced by two binary relationships, father and mother
Using
two binary relationships allows partial information (e.g. only mother being know) works-on
2.21
identifying entity set it must relate to the identifying entity set via a total, one-to-many
relationship set from the identifying to the weak entity set
attributes that distinguishes among all the entities of a weak entity set.
The primary key of a weak entity set is formed by the primary key
of the strong entity set on which the weak entity set is existence dependent, plus the weak entity sets discriminator.
2.22
11
dashed line.
payment-number discriminator of the payment entity set Primary key for payment (loan-number, payment-number)
2.23
stored with the weak entity set, since it is implicit in the identifying relationship.
If loan-number were explicitly stored, payment could be made a
strong entity, but then the relationship between payment and loan would be duplicated by an implicit relationship defined by the attribute loan-number common to payment and loan
2.24
12
course-number as an attribute. Then the relationship with course would be implicit in the coursenumber attribute
2.25
Specialization
Top-down design process; we designate subgroupings within an
entity set that are distinctive from other entities in the set.
These subgroupings become lower-level entity sets that have
attributes or participate in relationships that do not apply to the higher-level entity set.
Depicted by a triangle component labeled ISA (E.g. customer is a
person).
Attribute inheritance a lower-level entity set inherits all the
attributes and relationship participation of the higher-level entity set to which it is linked.
2.26
13
Specialization Example
2.27
Generalization
A bottom-up design process combine a number of entity sets
interchangeably.
2.28
14
different features.
E.g. permanent-employee vs. temporary-employee, in addition to
a member of one of permanent-employee or temporary-employee, and also a member of one of officer, secretary, or teller
The ISA relationship also referred to as superclass - subclass
relationship
2.29
entity can belong to only one lower-level entity set in E-R diagram by writing disjoint next to the ISA triangle entity can belong to more than one lower-level entity set
Overlapping
an
2.30
15
the higher-level entity set must belong to at least one of the lower-level entity sets within a generalization. total : an entity must belong to one of the lower-level entity sets partial: an entity need not belong to one of the lower-level entity
sets
2.31
Aggregation
Consider the ternary relationship works-on, which we saw earlier Suppose we want to record managers for tasks performed by an
employee at a branch
2.32
16
Aggregation (Cont.)
Relationship sets works-on and manages represent overlapping
information Every manages relationship corresponds to a works-on relationship However, some works-on relationships may not correspond to any
manages relationships
So
Treat relationship as an abstract entity Allows relationships between relationships Abstraction of relationship into new entity
Without introducing redundancy, the following diagram represents:
An employee works on a particular job at a particular branch An employee, branch, job combination may have an associated manager
2.33
2.34
17
or a relationship set.
The use of a ternary relationship versus a pair of binary
relationships.
The use of a strong or weak entity set. The use of specialization/generalization contributes to
single unit without concern for the details of its internal structure.
2.35
2.36
18
2.37
2.38
19
2.39
the keys of the participating entities. The candidate key for the table is determined by the cardinality constraints among participating entities.
4. A weak entity set becomes a table that includes a column
2.40
20
ManyMany-ToTo-One Relationships
Example of many-to-one relationships: a loan is associated with
several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
2.41
2.42
21
columns for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set.
E.g.: table for relationship set borrower
2.43
Redundancy of Tables
Table with equivalent keys can be merged together---as
in the 3NF design algorithm E.g.: Merge the tables account-branch with account
2.44
22
might be needed
2.45
for each component attribute E.g. given entity set customer with composite attribute name with
component attributes first-name and last-name the table corresponding to the entity set has two attributes name.first-name and name.last-name
2.46
23
2.47
Drawback: getting information about, e.g., employee requires accessing two tables
2.48
24
Drawback: street and city may be stored redundantly for persons who are both customers and employees
2.49
2.50
25
works-on and entity set manager, create a table manages(employee-id, branch-name, title, manager-name)
Table works-on is redundant provided we are willing to store
2.51
End of Chapter 2
26