CH 7
CH 7
Model
Database System Concepts - 6th Edition 7.1 ©Silberschatz, Korth and Sudarshan
Entity-Relationship Model
Design Process
Modeling
Constraints
E-R Diagram
Design Issues
Weak Entity Sets
Extended E-R Features
Design of the Bank Database
Reduction to Relation Schemas
Database Design
UML
Database System Concepts - 6th Edition 7.2 ©Silberschatz, Korth and Sudarshan
Modeling
Database System Concepts - 6th Edition 7.3 ©Silberschatz, Korth and Sudarshan
Entity Sets instructor and student
Database System Concepts - 6th Edition 7.4 ©Silberschatz, Korth and Sudarshan
Attributes
Database System Concepts - 6th Edition 7.5 ©Silberschatz, Korth and Sudarshan
Simple and composite attributes
1. Simple Attributes-
Simple attributes are those attributes which can not be divided further.
2. Composite Attributes-
Database System Concepts - 6th Edition 7.6 ©Silberschatz, Korth and Sudarshan
Composite Attributes
Database System Concepts - 6th Edition 7.7 ©Silberschatz, Korth and Sudarshan
Single-valued and multivalued attributes
Single Valued Attributes-
Single valued attributes are those attributes which can take only
one value for a given entity from an entity set.
Example-
Database System Concepts - 6th Edition 7.8 ©Silberschatz, Korth and Sudarshan
Single-valued and multivalued attributes
Multi valued attributes are those attributes which can take more
than one value for a given entity from an entity set.
Database System Concepts - 6th Edition 7.9 ©Silberschatz, Korth and Sudarshan
Derived Attributes
Derived Attributes-
Example-
Database System Concepts - 6th Edition 7.10 ©Silberschatz, Korth and Sudarshan
Key Attributes
Key Attributes-
Example-
Database System Concepts - 6th Edition 7.11 ©Silberschatz, Korth and Sudarshan
Relationship Sets
Database System Concepts - 6th Edition 7.12 ©Silberschatz, Korth and Sudarshan
Relationship Set advisor
Database System Concepts - 6th Edition 7.13 ©Silberschatz, Korth and Sudarshan
Relationship Sets (Cont.)
Database System Concepts - 6th Edition 7.14 ©Silberschatz, Korth and Sudarshan
Degree of a Relationship Set
binary relationship
involve two entity sets (or degree two).
most relationship sets in a database system are binary.
Relationships between more than two entity sets are rare. Most
relationships are binary. (More on this later.)
Example: students work on research projects under the
guidance of an instructor.
relationship proj_guide is a ternary relationship between
instructor, student, and project
Database System Concepts - 6th Edition 7.15 ©Silberschatz, Korth and Sudarshan
Mapping Cardinality Constraints
Express the number of entities to which another entity can be
associated via a relationship set.
Most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality must be one of
the following types:
One to one
One to many
Many to one
Many to many
Database System Concepts - 6th Edition 7.16 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Database System Concepts - 6th Edition 7.17 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Database System Concepts - 6th Edition 7.18 ©Silberschatz, Korth and Sudarshan
Keys
Database System Concepts - 6th Edition 7.19 ©Silberschatz, Korth and Sudarshan
Keys for Relationship Sets
Database System Concepts - 6th Edition 7.20 ©Silberschatz, Korth and Sudarshan
Redundant Attributes
Suppose we have entity sets
instructor, with attributes including dept_name
department
and a relationship
inst_dept relating instructor and department
Attribute dept_name in entity instructor is redundant since there is an
explicit relationship inst_dept which relates instructors to departments
The attribute replicates information present in the relationship, and
should be removed from instructor
BUT: when converting back to tables, in some cases the attribute
gets reintroduced, as we will see.
Database System Concepts - 6th Edition 7.21 ©Silberschatz, Korth and Sudarshan
E-R Diagrams
Database System Concepts - 6th Edition 7.22 ©Silberschatz, Korth and Sudarshan
Entity With Composite, Multivalued, and Derived
Attributes
Database System Concepts - 6th Edition 7.23 ©Silberschatz, Korth and Sudarshan
Relationship Sets with Attributes
Database System Concepts - 6th Edition 7.24 ©Silberschatz, Korth and Sudarshan
Roles
Database System Concepts - 6th Edition 7.25 ©Silberschatz, Korth and Sudarshan
Cardinality Constraints
Database System Concepts - 6th Edition 7.26 ©Silberschatz, Korth and Sudarshan
One-to-One Relationship
Database System Concepts - 6th Edition 7.27 ©Silberschatz, Korth and Sudarshan
One-to-Many Relationship
Database System Concepts - 6th Edition 7.28 ©Silberschatz, Korth and Sudarshan
Many-to-One Relationships
Database System Concepts - 6th Edition 7.29 ©Silberschatz, Korth and Sudarshan
Many-to-Many Relationship
An instructor is associated with several (possibly 0) students via
advisor
A student is associated with several (possibly 0) instructors via
advisor
Database System Concepts - 6th Edition 7.30 ©Silberschatz, Korth and Sudarshan
Participation of an Entity Set in a
Relationship Set
Total participation (indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship set. That is why, it is also
called as mandatory participation.
Total participation is represented using a double line between the entity set and
relationship set.
Database System Concepts - 6th Edition 7.31 ©Silberschatz, Korth and Sudarshan
Participation of an Entity Set in a Relationship
Set
Database System Concepts - 6th Edition 7.32 ©Silberschatz, Korth and Sudarshan
Relationship between Cardinality
and Participation Constraints
Database System Concepts - 6th Edition 7.33 ©Silberschatz, Korth and Sudarshan
E-R Diagram with a Ternary Relationship
Database System Concepts - 6th Edition 7.34 ©Silberschatz, Korth and Sudarshan
Cardinality Constraints on Ternary
Relationship
We allow at most one arrow out of a ternary (or greater degree)
relationship to indicate a cardinality constraint
E.g., an arrow from proj_guide to instructor indicates each student has
at most one guide for a project
If there is more than one arrow, there are two ways of defining the
meaning.
E.g., a ternary relationship R between A, B and C with arrows to B
and C could mean
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
Database System Concepts - 6th Edition 7.35 ©Silberschatz, Korth and Sudarshan
ER design
Database System Concepts - 6th Edition 7.36 ©Silberschatz, Korth and Sudarshan
Weak Entity Sets
Database System Concepts - 6th Edition 7.37 ©Silberschatz, Korth and Sudarshan
Weak Entity Sets (Cont.)
We underline the discriminator of a weak entity set with a dashed
line.
We put the identifying relationship of a weak entity in a double
diamond.
Primary key for section – (course_id, sec_id, semester, year)
Database System Concepts - 6th Edition 7.38 ©Silberschatz, Korth and Sudarshan
Weak Entity Sets (Cont.)
Note: the primary key of the strong entity set is not explicitly stored
with the weak entity set, since it is implicit in the identifying
relationship.
If course_id were explicitly stored, section could be made a strong
entity, but then the relationship between section and course would
be duplicated by an implicit relationship defined by the attribute
course_id common to course and section
Database System Concepts - 6th Edition 7.39 ©Silberschatz, Korth and Sudarshan
E-R Diagram for a University Enterprise
Database System Concepts - 6th Edition 7.40 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 7.41 ©Silberschatz, Korth and Sudarshan
Reduction to Relational Schemas
Database System Concepts - 6th Edition 7.42 ©Silberschatz, Korth and Sudarshan
Reduction to Relation Schemas
Entity sets and relationship sets can be expressed uniformly as
relation schemas that represent the contents of the database.
A database which conforms to an E-R diagram can be represented by
a collection of schemas.
For each entity set and relationship set there is a unique schema that
is assigned the name of the corresponding entity set or relationship
set.
Each schema has a number of columns (generally corresponding to
attributes), which have unique names.
Database System Concepts - 6th Edition 7.43 ©Silberschatz, Korth and Sudarshan
Representing Entity Sets With Simple
Attributes
Database System Concepts - 6th Edition 7.44 ©Silberschatz, Korth and Sudarshan
Representing Relationship Sets
Database System Concepts - 6th Edition 7.45 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas
Many-to-one and one-to-many relationship sets that are total on the
many-side can be represented by adding an extra attribute to the
“many” side, containing the primary key of the “one” side
Example: Instead of creating a schema for relationship set inst_dept,
add an attribute dept_name to the schema arising from entity set
instructor
Database System Concepts - 6th Edition 7.46 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas (Cont.)
Database System Concepts - 6th Edition 7.47 ©Silberschatz, Korth and Sudarshan
Composite and Multivalued Attributes
Composite attributes are flattened out by creating a
separate attribute for each component attribute
Example: given entity set instructor 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
Prefix omitted if there is no ambiguity
Ignoring multivalued attributes, extended instructor
schema is
instructor(ID,
first_name, middle_initial, last_name,
street_number, street_name,
apt_number, city, state, zip_code,
date_of_birth)
Database System Concepts - 6th Edition 7.48 ©Silberschatz, Korth and Sudarshan
Composite and Multivalued Attributes
Database System Concepts - 6th Edition 7.49 ©Silberschatz, Korth and Sudarshan
Multivalued Attributes (Cont.)
Special case:entity time_slot has only one attribute other than the
primary-key attribute, and that attribute is multivalued
Optimization: Don’t create the relation corresponding to the entity,
just create the one corresponding to the multivalued attribute
time_slot(time_slot_id, day, start_time, end_time)
Caveat: time_slot attribute of section (from sec_time_slot) cannot be
a foreign key due to this optimization
Database System Concepts - 6th Edition 7.50 ©Silberschatz, Korth and Sudarshan
Design Issues
Use of entity sets vs. attributes
Database System Concepts - 6th Edition 7.51 ©Silberschatz, Korth and Sudarshan
Design Issues
Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship set to describe an action
that occurs between entities
Database System Concepts - 6th Edition 7.52 ©Silberschatz, Korth and Sudarshan
Design Issues
Binary versus n-ary relationship sets
Although it is possible to replace any nonbinary (n-ary, for n > 2)
relationship set by a number of distinct binary relationship sets, a n-ary
relationship set shows more clearly that several entities participate in a
single relationship.
Placement of relationship attributes
e.g., attribute date as attribute of advisor or as attribute of student
Database System Concepts - 6th Edition 7.53 ©Silberschatz, Korth and Sudarshan
Binary Vs. Non-Binary Relationships
Database System Concepts - 6th Edition 7.54 ©Silberschatz, Korth and Sudarshan
Converting Non-Binary Relationships to Binary Form
Database System Concepts - 6th Edition 7.55 ©Silberschatz, Korth and Sudarshan
Converting Non-Binary Relationships
(Cont.)
Also need to translate constraints
Translating all constraints may not be possible
There may be instances in the translated schema that
cannot correspond to any instance of R
Exercise: add constraints to the relationships RA, RB and
RC to ensure that a newly created entity corresponds to
exactly one entity in each of entity sets A, B and C
We can avoid creating an identifying attribute by making E a
weak entity set (described shortly) identified by the three
relationship sets
Database System Concepts - 6th Edition 7.56 ©Silberschatz, Korth and Sudarshan
Extended ER Features
Database System Concepts - 6th Edition 7.57 ©Silberschatz, Korth and Sudarshan
Extended E-R Features: Specialization
Database System Concepts - 6th Edition 7.58 ©Silberschatz, Korth and Sudarshan
Specialization Example
Database System Concepts - 6th Edition 7.59 ©Silberschatz, Korth and Sudarshan
Extended ER Features: Generalization
A bottom-up design process – combine a number of entity sets
that share the same features into a higher-level entity set.
Specialization and generalization are simple inversions of each
other; they are represented in an E-R diagram in the same way.
The terms specialization and generalization are used
interchangeably.
Database System Concepts - 6th Edition 7.60 ©Silberschatz, Korth and Sudarshan
Specialization and Generalization (Cont.)
Database System Concepts - 6th Edition 7.61 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 7.62 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 6th Edition 7.63 ©Silberschatz, Korth and Sudarshan
Design Constraints on a
Specialization/Generalization
Constraint on which entities can be members of a given lower-level entity
set.
condition-defined
Example: all customers over 65 years are members of senior-
citizen entity set; senior-citizen ISA person.
user-defined
Constraint on whether or not entities may belong to more than one lower-
level entity set within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set
Noted in E-R diagram by having multiple lower-level entity sets link
to the same triangle
Overlapping
an entity can belong to more than one lower-level entity set
Database System Concepts - 6th Edition 7.64 ©Silberschatz, Korth and Sudarshan
Design Constraints on a
Specialization/Generalization (Cont.)
Completeness constraint -- specifies whether or not an entity in
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
Database System Concepts - 6th Edition 7.65 ©Silberschatz, Korth and Sudarshan
Aggregation
Database System Concepts - 6th Edition 7.66 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)
Database System Concepts - 6th Edition 7.67 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)
Without introducing redundancy, the following diagram represents:
A student is guided by a particular instructor on a particular project
A student, instructor, project combination may have an associated
evaluation
Database System Concepts - 6th Edition 7.68 ©Silberschatz, Korth and Sudarshan
Representing Specialization via
Schemas
Method 1:
Form a schema for the higher-level entity
Form a schema for each lower-level entity set, include primary key
of higher-level entity set and local attributes
schema attributes
person ID, name, street, city
student ID, tot_cred
employee ID, salary
Drawback: getting information about, an employee requires
accessing two relations, the one corresponding to the low-level
schema and the one corresponding to the high-level schema
Database System Concepts - 6th Edition 7.69 ©Silberschatz, Korth and Sudarshan
Representing Specialization as Schemas
(Cont.)
Method 2:
Form a schema for each entity set with all local and inherited attributes
schema attributes
person ID, name, street, city
student ID, name, street, city, tot_cred
employee ID, name, street, city, salary
If specialization is total, the schema for the generalized entity set
(person) not required to store information
Can be defined as a “view” relation containing union of
specialization relations
But explicit schema may still be needed for foreign key constraints
Drawback: name, street and city may be stored redundantly for people
who are both students and employees
Database System Concepts - 6th Edition 7.70 ©Silberschatz, Korth and Sudarshan
Schemas Corresponding to Aggregation
Database System Concepts - 6th Edition 7.71 ©Silberschatz, Korth and Sudarshan
Schemas Corresponding to
Aggregation (Cont.)
For example, to represent aggregation manages between
relationship works_on and entity set manager, create a schema
eval_for (s_ID, project_id, i_ID, evaluation_id)
Schema proj_guide is redundant provided we are willing to store null
values for attribute manager_name in relation on schema manages
Database System Concepts - 6th Edition 7.72 ©Silberschatz, Korth and Sudarshan
E-R Design Decisions
The use of an attribute or entity set to represent an object.
Whether a real-world concept is best expressed by an entity set 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 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 - 6th Edition 7.73 ©Silberschatz, Korth and Sudarshan
Summary of Symbols Used in E-R Notation
Database System Concepts - 6th Edition 7.74 ©Silberschatz, Korth and Sudarshan
Symbols Used in E-R Notation (Cont.)
Database System Concepts - 6th Edition 7.75 ©Silberschatz, Korth and Sudarshan
Alternative ER Notations
Chen, IDE1FX, …
Database System Concepts - 6th Edition 7.76 ©Silberschatz, Korth and Sudarshan
Alternative ER Notations
Database System Concepts - 6th Edition 7.77 ©Silberschatz, Korth and Sudarshan
UML
Database System Concepts - 6th Edition 7.78 ©Silberschatz, Korth and Sudarshan
ER vs. UML Class Diagrams
Database System Concepts - 6th Edition 7.79 ©Silberschatz, Korth and Sudarshan
ER vs. UML Class Diagrams
ER Diagram Notation Equivalent in UML
Database System Concepts - 6th Edition 7.81 ©Silberschatz, Korth and Sudarshan
Thank You
Database System Concepts - 6th Edition 7.82 ©Silberschatz, Korth and Sudarshan