CH 7
CH 7
Modeling
Constraints
E-R Diagram
Design Issues
Weak Entity Sets
Reduction to Relation Schemas
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
Relationship Sets
Database System Concepts - 6th Edition 7.5 ©Silberschatz, Korth and Sudarshan
Relationship Set advisor
Database System Concepts - 6th Edition 7.6 ©Silberschatz, Korth and Sudarshan
Relationship Sets (Cont.)
Database System Concepts - 6th Edition 7.7 ©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.8 ©Silberschatz, Korth and Sudarshan
Attributes
Database System Concepts - 6th Edition 7.9 ©Silberschatz, Korth and Sudarshan
Composite Attributes
Database System Concepts - 6th Edition 7.10 ©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.11 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Database System Concepts - 6th Edition 7.12 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Database System Concepts - 6th Edition 7.13 ©Silberschatz, Korth and Sudarshan
Keys
Database System Concepts - 6th Edition 7.14 ©Silberschatz, Korth and Sudarshan
Keys for Relationship Sets
Database System Concepts - 6th Edition 7.15 ©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.16 ©Silberschatz, Korth and Sudarshan
E-R Diagrams
Database System Concepts - 6th Edition 7.17 ©Silberschatz, Korth and Sudarshan
Entity With Composite, Multivalued, and Derived
Attributes
Database System Concepts - 6th Edition 7.18 ©Silberschatz, Korth and Sudarshan
Relationship Sets with Attributes
Database System Concepts - 6th Edition 7.19 ©Silberschatz, Korth and Sudarshan
Roles
Database System Concepts - 6th Edition 7.20 ©Silberschatz, Korth and Sudarshan
Cardinality Constraints
Database System Concepts - 6th Edition 7.21 ©Silberschatz, Korth and Sudarshan
One-to-One Relationship
Database System Concepts - 6th Edition 7.22 ©Silberschatz, Korth and Sudarshan
One-to-Many Relationship
Database System Concepts - 6th Edition 7.23 ©Silberschatz, Korth and Sudarshan
Many-to-One Relationships
Database System Concepts - 6th Edition 7.24 ©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.25 ©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
E.g., participation of section in sec_course is total
every section must have an associated course
Partial participation: some entities may not participate in any
relationship in the relationship set
Example: participation of instructor in advisor is partial
Database System Concepts - 6th Edition 7.26 ©Silberschatz, Korth and Sudarshan
Alternative Notation for Cardinality Limits
Database System Concepts - 6th Edition 7.27 ©Silberschatz, Korth and Sudarshan
E-R Diagram with a Ternary Relationship
Database System Concepts - 6th Edition 7.28 ©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.29 ©Silberschatz, Korth and Sudarshan
How about doing an ER design
interactively on the board?
Suggest an application to be modeled.
Database System Concepts - 6th Edition 7.31 ©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.32 ©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.33 ©Silberschatz, Korth and Sudarshan
E-R Diagram for a University Enterprise
Database System Concepts - 6th Edition 7.34 ©Silberschatz, Korth and Sudarshan
Reduction to Relational Schemas
Database System Concepts - 6th Edition 7.35 ©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.36 ©Silberschatz, Korth and Sudarshan
Representing Entity Sets With Simple
Attributes
A strong entity set reduces to a schema with the same attributes
student(ID, name, tot_cred)
A weak entity set becomes a table that includes a column for the primary
key of the identifying strong entity set
section ( course_id, sec_id, sem, year )
Database System Concepts - 6th Edition 7.37 ©Silberschatz, Korth and Sudarshan
Representing Relationship Sets
Database System Concepts - 6th Edition 7.38 ©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.39 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas (Cont.)
Database System Concepts - 6th Edition 7.40 ©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.41 ©Silberschatz, Korth and Sudarshan
Composite and Multivalued Attributes
Database System Concepts - 6th Edition 7.42 ©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.43 ©Silberschatz, Korth and Sudarshan
Design Issues
Use of entity sets vs. attributes
Database System Concepts - 6th Edition 7.44 ©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.45 ©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.46 ©Silberschatz, Korth and Sudarshan
Binary Vs. Non-Binary Relationships
Database System Concepts - 6th Edition 7.47 ©Silberschatz, Korth and Sudarshan
Converting Non-Binary Relationships to Binary Form
Database System Concepts - 6th Edition 7.48 ©Silberschatz, Korth and Sudarshan
End of Chapter 7