DB Design Using ER Model
DB Design Using ER Model
DB Design Using ER Model
(Fall 2022)
Database Design Using E-R Model
Asst.Prof.Dr. Hasan ÇİFCİ
Agenda
2/90
Design Phases
• Initial phase -- characterize fully the data needs of the prospective database users.
• Second phase -- choosing a data model
– Applying the concepts of the chosen data model
– Translating these requirements into a conceptual schema of the database.
– A fully developed conceptual schema indicates the functional requirements of
the enterprise.
• Describe the kinds of operations (or transactions) that will be performed
on the data.
▪ Final Phase -- Moving from an abstract data model to the implementation of the
database
– Logical Design – Deciding on the database schema.
• Database design requires that we find a “good” collection of relation
schemas.
▪ Business decision – What attributes should we record in the database?
▪ Computer science decision – What relation schemas should we have and
how should the attributes be distributed among the various relation
schemas?
– Physical Design – Deciding on the physical layout of the database
3/90
Design Alternatives
4/90
Design Approaches
5/90
Outline of the ER Model
6/90
ER Model - Database Modeling
7/90
Entity Sets
8/90
Entity Sets - instructor and student
9/90
Representing Entity Sets in ER Diagram
10/90
Relationship Sets
11/90
Relationship Sets
12/90
Representing Relationship Sets via ER
Diagrams
13/90
Relationship Sets
student 14/90
Relationship Sets with Attributes
15/90
Roles
16/90
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.
17/90
Non-binary Relationship Sets
• Attribute types:
– Simple and composite attributes.
– Single-valued and multivalued attributes
• Example: multivalued attribute: phone_numbers
– Derived attributes
• Can be computed from other attributes
• Example: age is derived from date_of_birth
• Domain – the set of permitted values for each attribute
19/90
Composite Attributes
component
attributes
street_number street_name apartment_number
20/90
Representing Complex Attributes in ER Diagram
21/90
Mapping Cardinality Constraints
22/90
Mapping Cardinalities
23/90
Mapping Cardinalities
24/90
Representing Cardinality Constraints in
ER Diagram
• 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.
• One-to-one relationship between an instructor and a student:
– A student is associated with at most one instructor via the
relationship advisor
– An instructor is associated with at most one student via advisor
25/90
One-to-Many Relationship
26/90
Many-to-One Relationships
27/90
Many-to-Many Relationship
28/90
Total and Partial Participation
29/90
Notation for Expressing More Complex
Constraints
▪ A line may have an associated minimum and maximum cardinality,
shown in the form l..h, where l is the minimum and h the maximum
cardinality
• A minimum value of 1 indicates total participation.
• A maximum value of 1 indicates that the entity participates in at
most one relationship
• A maximum value of * indicates no limit.
▪ Example
31/90
Cardinality Constraints on Ternary
Relationship
• If there is more than one arrow, there are two ways of defining the
meaning.
– For example, 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
A R B
32/90
Primary Key
33/90
Primary Key for Entity Sets
34/90
Primary Key for Relationship Sets
35/90
Choice of Primary Key for Binary Relationship
36/90
Weak Entity Sets
• An entity set that does not have a primary key is referred to as a weak
entity set.
• The existence of a weak entity set depends on the existence of a
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
– Identifying relationship depicted using a double diamond
• 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 set’s discriminator.
37/90
Weak Entity Sets
38/90
Weak Entity Sets
39/90
Weak Entity Sets
• An entity set that is not a weak entity set is termed a strong entity set.
• Every weak entity must be associated with an identifying entity; that
is, the weak entity set is said to be existence dependent on the
identifying entity set.
• The identifying entity set is said to own the weak entity set that it
identifies.
• The relationship associating the weak entity set with the identifying
entity set is called the identifying relationship.
• Note that the relational schema we eventually create from the entity
set section does have the attribute course_id, for reasons that will
become clear later, even though we have dropped the attribute
course_id from the entity set section.
40/90
Expressing Weak Entity Sets
41/90
Expressing Weak Entity Sets
42/90
Redundant Attributes
• Suppose we have entity sets:
– student, with attributes: ID, name, tot_cred, dept_name
– department, with attributes: dept_name, building, budget
• We model the fact that each student has an associated department using a
relationship set stud_dept
• The attribute dept_name in student below replicates information present in
the relationship and is therefore redundant
– and needs to be removed.
• BUT: when converting back to tables, in some cases the attribute gets
reintroduced, as we will see later.
43/90
E-R Diagram for a University Enterprise
44/90
Reduction to Relation Schemas
45/90
Reduction to Relation Schemas
46/90
Representing Entity Sets
Section
Student
sec_id
ID
takes sem
name year
tot_cred
47/90
Representation of Entity Sets with
Composite 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
(name_first_name could be first_name)
▪ Ignoring multivalued attributes, extended instructor
schema is
• instructor(ID,
first_name, middle_initial, last_name,
street_number, street_name,
apt_number, city, state, zip, date_of_birth)
48/90
Representation of Entity Sets with
Multivalued Attributes
▪ A multivalued attribute M of an entity E is represented by a separate
schema EM
▪ Schema EM has attributes corresponding to the primary key of E and
an attribute corresponding to multivalued attribute M
▪ Example: Multivalued attribute phone_number of instructor is
represented by a schema:
inst_phone= (ID, phone_number)
▪ Each value of the multivalued attribute maps to a separate tuple of
the relation on schema EM
• For example, an instructor entity with primary key 22222 and
phone numbers 456-7890 and 123-4567 maps to two tuples:
(22222, 456-7890) and (22222, 123-4567)
49/90
Representing Relationship Sets
50/90
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
▪ Example
51/90
Redundancy of Schemas
▪ For one-to-one relationship sets, either side can be chosen to act as the
“many” side
• That is, an extra attribute can be added to either of the tables
corresponding to the two entity sets
▪ If participation is partial on the “many” side, replacing a schema by an extra
attribute in the schema corresponding to the “many” side could result in null
values
▪ The schema corresponding to a relationship set linking a weak entity set to
its identifying strong entity set is redundant.
▪ Example: The section schema already contains the attributes that would
appear in the sec_course schema
52/90
Extended E-R Features
53/90
Specialization
54/90
Specialization Example
• In an incomplete specialization, also called
a partial specialization, only some
individuals of the parent class are
specialized (that is, have unique
attributes). Other individuals of the parent
class have only the common attributes.
• In a complete specialization, all individuals
of the parent class have one or more
unique attributes that are not common to
the generalized (parent) class.
• In an overlapping specialization, an
individual of the parent class may be a
member of more than one of the
specialized subclasses.
• In a disjoint specialization, also called an
exclusive specialization, an individual of
the parent class may be a member of only
one specialized subclass.
Overlapping – employee and student
Disjoint – instructor and secretary
55/90
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
56/90
Representing Specialization as Schemas
▪ Method 2:
• Form a schema for each entity set with all local and inherited
attributes
57/90
Generalization
58/90
Completeness Constraint
59/90
Completeness Constraint
60/90
Aggregation
▪ Aggregation is an abstraction through which we can represent
relationships as higher level entity sets.
▪ Consider the ternary relationship proj_guide, which we saw earlier
▪ Suppose we want to record evaluations of a student by a guide on
a project
61/90
Aggregation
62/90
Aggregation
▪ Eliminate this redundancy via aggregation 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
63/90
Aggregation - Another Example
64/90
Reduction to Relational Schemas
65/90
Design Issues
66/90
Common Mistakes in E-R Diagrams
▪ Example of erroneous E-R diagrams
67/90
Common Mistakes in E-R Diagrams
68/90
Entities vs. Attributes
69/90
Entities vs. Relationship Sets
▪ Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship set to describe
an action that occurs between entities
70/90
Binary vs. Non-Binary Relationships
71/90
Converting Non-Binary Relationships to
Binary Form
• In general, any non-binary relationship can be represented using binary
relationships by creating an artificial entity set.
– Replace R between entity sets A, B and C by an entity set E, and three
relationship sets:
1. RA, relating E and A 2. RB, relating E and B
3. RC, relating E and C
– Create an identifying attribute for E and add any attributes of R to E
– For each relationship (ai , bi , ci) in R, create
1. a new entity ei in the entity set E 2. add (ei , ai ) to RA
3. add (ei , bi ) to RB 4. add (ei , ci ) to RC
72/90
Converting Non-Binary Relationships
73/90
E-R Design Decisions
74/90
Summary of Symbols Used in E-R
Notation
75/90
Symbols Used in E-R Notation
76/90
Alternative ER Notations
• Chen, IDE1FX, …
77/90
Alternative ER Notations
78/90
Unified Modeling Language (UML)
79/90
ER vs. UML Class Diagrams
82/90
ER vs. UML Class Diagrams
83/90
Other Aspects of Database Design
85/90
Exercises (1)
86/90
Exercises (2)
87/90
Exercises (2.a)
Answer for “a”
88/90
Exercises (2.b)
Answer for “b”
89/90
Thank you…
Hasan ÇİFCİ