Chapter 6: Entity - Relationship Model
Chapter 6: Entity - Relationship Model
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.2
Modeling
A database can be modeled as:
z
a collection of entities,
objects.
z
An entity set is a set of entities of the same type that share the same
properties.
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.3
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.4
loan_
number
amount
Relationship Sets
A relationship is an association among several entities
Example:
Hayes
customer entity
depositor
relationship set
A-102
account entity
Example:
(Hayes, A-102) depositor
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.5
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.6
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.7
set.
Relationship sets that involve two entity sets are binary (or
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.8
Attributes
An entity is represented by a set of attributes, that is descriptive
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:
z
Derived attributes
Can
Example:
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.9
Composite Attributes
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.10
One to one
One to many
Many to one
Many to many
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.11
Mapping Cardinalities
One to one
One to many
6.12
Mapping Cardinalities
Many to one
Many to many
6.13
Keys
A super key of an entity set is a set of one or more attributes
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.14
NOTE: this means a pair of entity sets can have at most one
relationship in a particular relationship set.
Example:
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.15
E-R Diagrams
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.16
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.17
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.18
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
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.19
Cardinality Constraints
We express cardinality constraints by drawing either a directed line (),
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.20
One-To-Many Relationship
In the one-to-many relationship a loan is associated with at most one
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.21
Many-To-One Relationships
In a many-to-one relationship a loan is associated with several
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.22
Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via
borrower
A loan is associated with several (possibly 0) customers via
borrower
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.23
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.24
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.25
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.26
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.27
Design Issues
Use of entity sets vs. attributes
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.28
works_on
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.29
Database System Concepts, 5th Ed., slide version 5.0, June 2005
2. add (ei , ai ) to RA
4. add (ei , ci ) to RC
6.30
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.31
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.32
entity set.
The existence of a weak entity set depends on the existence of a
The discriminator (or partial key) of a weak entity set is the set of
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.
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.34
line.
payment_number discriminator of the payment entity set
Primary key for payment (loan_number, payment_number)
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.35
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
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.36
course_number as an attribute.
Then the relationship with course would be implicit in the
course_number attribute
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.37
person).
Attribute inheritance a lower-level entity set inherits all the attributes
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.38
Specialization Example
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.39
interchangeably.
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.40
features.
E.g. permanent_employee vs. temporary_employee, in addition to
relationship
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.41
Design Constraints on a
Specialization/Generalization
Constraint on which entities can be members of a given lower-level
entity set.
z
condition-defined
Example:
user-defined
Disjoint
an
Noted
Overlapping
an
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.42
Design Constraints on a
Specialization/Generalization (Cont.)
Completeness constraint -- specifies whether or not an
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.43
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
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.44
Aggregation (Cont.)
Relationship sets works_on and manages represent overlapping information
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.45
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.46
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 modularity
in the design.
The use of aggregation can treat the aggregate entity set as a
single unit without concern for the details of its internal structure.
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.47
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.48
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.50
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.51
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.52
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.53
attributes for the primary keys of the two participating entity sets,
and any descriptive attributes of the relationship set.
Example: schema for relationship set borrower
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.54
Redundancy of Schemas
Many-to-one and one-to-many relationship sets that are total on the
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.55
many side
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.56
Example: given entity set customer with composite attribute name with
component attributes first_name and last_name the schema
corresponding to the entity set has two attributes
name.first_name and name.last_name
schema EM
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.57
attributes
name, street, city
name, credit_rating
name, salary
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.58
Form a schema for each entity set with all local and inherited attributes
schema
person
customer
employee
attributes
name, street, city
name, street, city, credit_rating
name, street, city, salary
But
z
Drawback: street and city may be stored redundantly for people who are
both customers and employees
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.59
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.60
Schemas Corresponding to
Aggregation (Cont.)
For example, to represent aggregation manages between
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.61
UML
UML: Unified Modeling Language
UML has many components to graphically model different aspects of an
differences.
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.62
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.63
connecting the entity sets. The relationship set name is written adjacent
to the line.
The role played by an entity set in a relationship set may also be
specified by writing the role name on the line, adjacent to the entity set.
The relationship set name may alternatively be written in a box, along
with attributes of the relationship set, and the box is connected, using a
dotted line, to the line depicting the relationship set.
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.64
overlapping
disjoint
6.65
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.66
End of Chapter 2
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.68
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.69
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.70
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.71
Existence Dependencies
If the existence of entity x depends on the existence of entity y,
loan
loan-payment
payment
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.72
Figure 6.8
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.73
Figure 6.15
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.74
Figure 6.16
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.75
Figure 6.26
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.76
Figure 6.27
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.77
Figure 6.28
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.78
Figure 6.29
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.79
Figure 6.30
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.80
Figure 6.31
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.81
Database System Concepts, 5th Ed., slide version 5.0, June 2005
6.82