Uploaded by Kais Yoo

Lecture 03and04

advertisement
DBS – The Entity Relationship Model
Database Systems
The Entity Relationship Model
Dr. Rudra Pratap Deb Nath
Department of Computer Science
and Engineering
University of Chittagong
rudra@cu.ac.bd
4th Semester 2022
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2021
1 / 111
DBS – The Entity Relationship Model
Learning goals
Goals
Create non-trivial ER diagrams
Assess the quality of an ER diagram
Perform and explain the mapping of ER diagrams to relations
Use a particular ER notation properly
Motivation
ER diagrams are used widely
ER model is easy to learn
Much simpler than UML
An ER diagram is a good communication tool
Talking the same language
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
2 / 111
DBS – The Entity Relationship Model
Database design
Outline I
1
Database design
Steps of database design
Example design
2
Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
3
Characteristics of relationship types
Degree
Chen notation (cardinality ratio)
Participation constraint
Chen notation (cardinality ratios) for nary relationship types
[min, max] notation (cardinality limits)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
2 / 111
DBS – The Entity Relationship Model
Database design
Outline II
4
Additional concepts
Weak entity types
The isa relationship type
5
Alternative notations
6
Mapping basic concepts to relations
Entity types
Relationship types
7
Mapping additional concepts to relations
Weak entity types
Recursive relationship types
N-ary relationship types
Special attributes
Generalization
Christian S. Jensen
DBS – The Entity Relationship Model
4th Semester 2022
3 / 111
DBS – The Entity Relationship Model
Database design
Outline III
8
Example schemas
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
4 / 111
DBS – The Entity Relationship Model
Database design
Steps of database design
Steps of database design
Requirements analysis
Parts of the real world
Manual/intelectual
modeling
Mapping onto a
conceptual schema
Conceptual schema
(ER schema)
Mapping onto a
data model
Semi-automatic
transformation
Relational
schema
Dr. Rudra Pratap Deb Nath
XML
schema
DBS – The Entity Relationship Model
Object-oriented
schema
4th Semester 2022
4 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 1: Requirements analysis
http://www.cu.ac.bd/
https://cu.ac.bd/dept/facultyprofile.php?
secno=2&menumapno=130
Processes to model
“Students take courses”
“Instructors offer courses”
“The student ID unambiguously identifies a student”
...
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
5 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 1: Requirements analysis – object specification
Employees
Attributes: EmpNo, salary, rank
EmpNo
Type: char
Length: 9
Domain: 0. . . 999.999.99
Degree of availability: 100%
Uniqueness: true
Dr. Rudra Pratap Deb Nath
Salary
Type: decimal
Length: (8,2)
Degree of availability: 10%
Uniqueness: no
Rank
Type: String
Length: 4
Degree of availability: 100%
Uniqueness: no
DBS – The Entity Relationship Model
4th Semester 2022
6 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 1: Requirements analysis – relationship
specification
Relationship: “grades”
Participating objects
Instructor as examiner
Student as examinee
Course as topic
Attributes of relationship “grades”
Date
Time
Grade
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
7 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 2: Mapping onto a conceptual model
Requirements
“Students take courses”
“Instructors offer courses”
“The student ID unambiguously identifies a student”
...
Functional requirements
Secretary needs to feed in the grades
...
⇓ Mapping
name
empID
instructor
student
studID
name
offers
lecture
takes
courseID
title
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
8 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 3: Mapping onto a data model
http://en.wikipedia.org/wiki/Database_model
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
9 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 3: Mapping onto the relational model
name
empID
instructor
student
studID
name
offers
takes
lecture
courseID
title
⇓ Mapping
Relational model
student (studID: integer, name: string)
takes (studID: integer, courseID: integer)
lecture (courseID: integer, title: string)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
10 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 4: Realization and implementation
Relational model
student (studID: integer, name: string)
takes (studID: integer, courseID: integer)
lecture (courseID: integer, title: string)
⇓ Mapping
Tables in a DB
student
studID
name
26120 Pedersen
25403
Hansen
...
...
Dr. Rudra Pratap Deb Nath
takes
studID courseID
25403
5022
26120
5001
...
...
lecture
courseID
5001
5022
...
DBS – The Entity Relationship Model
title
DBS
Belief and Knowledge
...
4th Semester 2022
11 / 111
DBS – The Entity Relationship Model
Database design
Example design
Step 4: Realization and implementation
Tables in a DB
student
studID
name
26120 Pedersen
25403
Hansen
...
...
takes
studID courseID
25403
5022
26120
5001
...
...
lecture
courseID
5001
5022
...
title
DBS
Belief and Knowledge
...
⇓ Mapping
Memory, pages, data structures, indexes, files, devices
http://en.wikipedia.org
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
12 / 111
DBS – The Entity Relationship Model
Database design
Example design
Steps of database design
1
Requirements analysis
What are we dealing with?
2
Mapping onto a conceptual model (conceptual design)
What data and relationships have to be captured?
3
Mapping onto a data model (logical design)
How to structure data in a specific model (here: the relational
model)?
4
Realization and implementation (physical design)
Which adaptations and optimizations does a specific DBMS require?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
13 / 111
DBS – The Entity Relationship Model
Database design
Example design
Steps of database design
1
Requirements analysis
What are we dealing with?
2
Mapping onto a conceptual model (conceptual design)
What data and relationships have to be captured?
3
Mapping onto a data model (logical design)
How to structure data in a specific model (here: the relational
model)?
4
Realization and implementation (physical design)
Which adaptations and optimizations does a specific DBMS require?
A good design avoids redundancy and incompleteness.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
13 / 111
DBS – The Entity Relationship Model
Basic concepts
Outline
1
Database design
2
Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
3
Characteristics of relationship types
4
Additional concepts
5
Alternative notations
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
13 / 111
DBS – The Entity Relationship Model
Basic concepts
Entity Relationship Model (ERM)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
14 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
Example scenarios
Example scenarios used on the slides
University: students, instructors, courses,. . .
Wine: wine, producers, regions,. . .
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
15 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
Wine schema
color
name
country
region
name
grapeType
description
area
side
Order
percentage
madeOf
dish
locatedIn
name
recommends
color
produces
wine
residual
Sweetness
year
producer
vineyard
critic
address
owns
name
licenseID
organization
license
amount
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
16 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
University schema (different from the book!)
department
empID
assistant
name
worksFor
grades
name
empID
semester
instructor
student
studID
name
takes
teaches
ects
successor
course
requires
courseID
predecessor
title
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
17 / 111
DBS – The Entity Relationship Model
Basic concepts
Entity types
Entities and entity types
Entities are objects of the real world about which we want to store
information
Only characteristics of entities can be stored in a database
(description), not the entity itself!
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
18 / 111
DBS – The Entity Relationship Model
Basic concepts
Entity types
Entities and entity types
Entities are objects of the real world about which we want to store
information
Only characteristics of entities can be stored in a database
(description), not the entity itself!
Entities are grouped into entity types.
wine
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
18 / 111
DBS – The Entity Relationship Model
Basic concepts
Entity types
Entities and entity types
Entities are objects of the real world about which we want to store
information
Only characteristics of entities can be stored in a database
(description), not the entity itself!
Entities are grouped into entity types.
wine
The extension of an entity type (entity set) is a particular collection of
entities.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
18 / 111
DBS – The Entity Relationship Model
Basic concepts
Entity types
Entities and entity types
Entities are objects of the real world about which we want to store
information
Only characteristics of entities can be stored in a database
(description), not the entity itself!
Entities are grouped into entity types.
wine
The extension of an entity type (entity set) is a particular collection of
entities.
Often the two terms entity set and entity type are used as synonyms (also
in the book).
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
18 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
Attributes model characteristics of entities or relationships.
All entities of an entity type have the same characteristics
Attributes are declared for entity types
Attributes have a domain or value set
color
name
year
wine
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
19 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
Single-valued vs. multi-valued attributes
A person might have multiple phone numbers (or a single one)
person
Dr. Rudra Pratap Deb Nath
phone
number
person
DBS – The Entity Relationship Model
phone
number
4th Semester 2022
20 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
Simple attributes vs. composite attributes
An address can be modeled as a string or composed of street and city
street
person
address
person
address
city
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
21 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
Stored attributes vs. derived attributes
E.g.: birthdate and age
birthday
person
age
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
22 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Keys
A (super) key consists of a subset of an entity type’s attributes
E(A1 , . . . , Am )
{S1 , . . . , Sk } ⊆ {A1 , . . . , Am }
The attributes S1 , . . . , Sk of the key are called key attributes.
The key attribute’s values uniquely identify an individual entity.
A candidate key corresponds to a minimal subset of attributes that fulfills
the above condition.
If there are multiple candidate keys, one is chosen as primary key.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
23 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
Primary key attributes are marked by underlining.
color
name
wineID
Dr. Rudra Pratap Deb Nath
year
wine
DBS – The Entity Relationship Model
4th Semester 2022
24 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
Primary key attributes are marked by underlining.
color
name
year
wineID
Dr. Rudra Pratap Deb Nath
wine
DBS – The Entity Relationship Model
4th Semester 2022
24 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
Primary key attributes are marked by underlining.
color
name
wineID
Dr. Rudra Pratap Deb Nath
year
wine
DBS – The Entity Relationship Model
4th Semester 2022
24 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Relationships and relationship types
Relationships describe connections between entities.
Relationships between entities are grouped into relationship types.
producer
produces
wine
An association between two or more entities is called relationship
(instance). A relationship set is a collection of relationship instances.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
25 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Relationships and relationship types
Relationships describe connections between entities.
Relationships between entities are grouped into relationship types.
producer
produces
wine
An association between two or more entities is called relationship
(instance). A relationship set is a collection of relationship instances.
Often the two terms relationship set and relationship type are used as
synonyms (also in the book).
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
25 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Mathematical understanding of relationship types
A relationship type R between entity types E1 , E2 , . . . , En can be
considered a mathematical relation.
Instance of a relationship type R:
R ⊆ E1 × E2 × · · · × En
A particular element (e1 , e2 , . . . , en ) ∈ R is called an instance of the
relationship type with ei ∈ Ei for all 1 ≤ i ≤ n.
Hint: This notation does not cover attributes of relationship types.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
26 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Recursive relationship types and role names
Role names are optional and used to characterize a relationship type.
Especially useful for recursive relationship types, i.e., an entity type is
participating multiple times in a relationship type.
wife
person
marriedTo
husband
sequel
sequelOf
movie
original
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
27 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Attributes of relationship types
Relationship types can also have (descriptive) attributes.
percentage
wine
Dr. Rudra Pratap Deb Nath
madeOf
grapeType
DBS – The Entity Relationship Model
4th Semester 2022
28 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
student
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
student
2. Relationship
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
student
2. Relationship → Relationship type
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
student
2. Relationship → Relationship type
takes
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
1. Entity → Entity type
student
2. Relationship → Relationship type
3. Attribute
takes
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
1. Entity → Entity type
name
semester
2. Relationship → Relationship type
student
3. Attribute
takes
course
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
name
semester
1. Entity → Entity type
student
2. Relationship → Relationship type
takes
3. Attribute
course
ects
title
courseID
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
name
semester
1. Entity → Entity type
student
2. Relationship → Relationship type
takes
3. Attribute
4. Primary key
course
ects
title
courseID
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
name
semester
1. Entity → Entity type
student
2. Relationship → Relationship type
takes
3. Attribute
4. Primary key
course
ects
title
courseID
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
name
semester
1. Entity → Entity type
student
2. Relationship → Relationship type
takes
3. Attribute
4. Primary key
5. Role
course
ects
title
courseID
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Summary: basic concepts
students take courses
studID
name
semester
1. Entity → Entity type
student
2. Relationship → Relationship type
participant
takes
3. Attribute
regular course
4. Primary key
5. Role
course
ects
title
courseID
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Outline
1
Database design
2
Basic concepts
3
Characteristics of relationship types
Degree
Chen notation (cardinality ratio)
Participation constraint
Chen notation (cardinality ratios) for nary relationship types
[min, max] notation (cardinality limits)
4
Additional concepts
5
Alternative
notations
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
29 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Characteristics of relationship types
Degree
Number of participating entity types
Mostly: binary
Rarely: ternary
In general: n-ary or n-way (multiway relationship types)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Characteristics of relationship types
Degree
Number of participating entity types
Mostly: binary
Rarely: ternary
In general: n-ary or n-way (multiway relationship types)
Cardinality ratio / cardinality limits / participation constraint
Number of times entities are involved in relationship instances
Cardinality ratio (Chen notation): 1:1, 1:N, N:M
Participation constraint: partial or total
Cardinality limits ([min,max] notation): [min,max]
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Characteristics of relationship types
Degree
Number of participating entity types
Mostly: binary
Rarely: ternary
In general: n-ary or n-way (multiway relationship types)
Cardinality ratio / cardinality limits / participation constraint
Number of times entities are involved in relationship instances
Cardinality ratio (Chen notation): 1:1, 1:N, N:M
Participation constraint: partial or total
Cardinality limits ([min,max] notation): [min,max]
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Multiway relationship types
Three binary relationship types
Ternary relationship type
dish
recommends
critic
Dr. Rudra Pratap Deb Nath
wine
dish
d-w
d-c
wine
critic
c-w
DBS – The Entity Relationship Model
4th Semester 2022
31 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Multiway relationship types
Ternary relationship type
Three binary relationship types
d1
w1
d1
w1
d2
w2
d2
w2
wine
dish
c1
c2
c1
critic
Dr. Rudra Pratap Deb Nath
wine
dish
c2
critic
DBS – The Entity Relationship Model
4th Semester 2022
32 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Reconstruction of relationship instances
Binary relationship types
d1
w1
d2
w2
Reconstructible relationship
instances
d1 – c1 – w1
d1 – c2 – w2
d2 – c2 – w1
dish
wine
c1
Dr. Rudra Pratap Deb Nath
but also: d1 – c2 – w1
c2
DBS – The Entity Relationship Model
4th Semester 2022
33 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Binary vs. n-ary relationship types
Ternary relationship type
d1
w1
d2
w2
wine
dish
c1
Using binary relationships we
can reconstruct the
relationship instance
d1 – c2 – w1
which is not contained in the
ternary relationship type!
c2
critic
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
33 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
Characteristics of relationship types
Degree
Number of participating entity types
Mostly: binary
Rarely: ternary
In general: n-ary or n-way (multiway relationship types)
Cardinality ratio / cardinality limits / participation constraint
Number of entities involved in a relationship instance
Cardinality ratio (Chen notation): 1:1, 1:N, N:M
Participation constraint: partial or total
Cardinality limits ([min,max] notation): [min,max]
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
34 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
Chen notation (cardinality ratio)
R ⊆ E1 × E2
E1
R
E2
1:1
1:N
1: at most one
N: arbitrary number
E1
E2
E1
E2
N:1
N:M
E1
E2
Dr. Rudra Pratap Deb Nath
E1
E2
DBS – The Entity Relationship Model
4th Semester 2022
35 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
Functional relationships
1:1, 1:N, and N:1 can be considered a partial functions (often also a total
function)
1:1 relationship: R : E1 →
7 E2 and R−1 : E2 →
7 E1
1:N relationship: R−1 : E2 →
7 E1
N:1 relationship: R : E1 →
7 E2
also referred to as functional relationship.
The “direction” is important!
The function always leads from the “N” entity type to the “1” entity type.
In the context of this lecture, we do not distinguish between partial (→)
7
and total functions (→). Hence, we simply write →.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
36 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
Graphical notation
1:N relationship type
producer
produces
wine
owns
license
1:1 relationship type
producer
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
37 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Participation constraint
Participation constraint
Total
Each entity of an entity type must participate in a relationship, i.e., it
cannot exist without any participation (E2 in the left example).
E1
E2
E1
E2
Partial
Each entity of an entity type can participate in a relationship, i.e., it can
exist without any participation.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
38 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Participation constraint
Graphical notation
1:N relationship type with total participation of entity type wine
producer
produces
wine
1:N relationship type with total participation of both involved entity types
producer
produces
wine
1:1 relationship type with partial participation
producer
Dr. Rudra Pratap Deb Nath
owns
DBS – The Entity Relationship Model
license
4th Semester 2022
39 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Overview cardinality ratios
student
takes
course
Which relationship type is it?
N:M
How many students are there in a course?
arbitrary
How many courses does a student take?
arbitrary
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
40 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Overview cardinality ratios
student
takes
course
Which relationship type is it?
1:N
How many students are there in a course?
at most one
How many courses does a student take?
arbitrary
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
41 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Overview cardinality ratios
student
takes
course
Which relationship type is it?
N:1
How many students are there in a course?
arbitrary
How many courses does a student take?
at most one
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
42 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Overview cardinality ratios
student
takes
course
Which relationship type is it?
1:1
How many students are there in a course?
at most one
How many courses does a student take?
at most one
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
43 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratios) for nary relationship types
Cardinality ratios for n-ary relationship types
E1
P
En
N
R
M
E2
1
Ek
R : E1 × E2 × ... × Ek−1 × Ek+1 × ... × En → Ek
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
44 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratios) for nary relationship types
Cardinality ratios for n-ary relationship types
E1
P
En
N
R
M
E2
1
Ek
R : E1 × E2 × ... × Ek−1 × Ek+1 × ... × En → Ek
Remark on notation in general
Using arrows or annotating lines with 1, N, M, etc. is equivalent.
Having both is not necessary but sometimes useful for clarification.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
44 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratios) for nary relationship types
Example relationship: supervises
professor
1
student
N
supervises
1
seminarTopic
grades
supervises: professor × student → seminarTopic
supervises: seminarTopic × student → professor
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
45 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Characteristics of relationship types
Degree
Number of participating entity types
Mostly: binary
Rarely: ternary
In general: n-ary or n-way (multiway relationship types)
Cardinality ratio / cardinality limits / participation constraint
Number of entities involved in a relationship instance
Cardinality ratio (Chen notation): 1:1, 1:N, N:M
Participation constraint: partial or total
Cardinality limits ([min,max] notation): [min,max]
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
46 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min,max] notation (cardinality limits)
E1
[min1, max1]
[minn, maxn]
R
En
[min2, max2]
E2
Restricts the number of times an entity can participate in a relationship.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
47 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min,max] notation (cardinality limits)
E1
[min1, max1]
[minn, maxn]
R
En
[min2, max2]
E2
R ⊆ E1 × E2 × ... × Ei × ... × En
For each ei ∈ Ei there exists
at least mini instances of relationship type R involving ei and
at most maxi instances of relationship type R involving ei
Cardinality constraint: mini ≤ |{r | r ∈ R ∧ r.Ei = ei }| ≤ maxi
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
47 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min,max] notation (cardinality limits)
E1
[min1, max1]
[minn, maxn]
R
En
[min2, max2]
E2
Special values for mini : 0
Special values for maxi : ∗
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
48 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min,max] notation (cardinality limits)
E1
[min1, max1]
[minn, maxn]
R
En
[min2, max2]
E2
Special values for mini : 0
Special values for maxi : ∗
[0, ∗] represents no restrictions → default
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
48 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min,max] notation (cardinality limits)
E1
[min1, max1]
[minn, maxn]
R
En
[min2, max2]
E2
Special values for mini : 0
Special values for maxi : ∗
[0, ∗] represents no restrictions → default
The book uses a slightly different notation: 1..* instead of [1, ∗]
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
48 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Chen notation vs [min,max] notation
1:1 relationship type
E1
Dr. Rudra Pratap Deb Nath
[0, 1]
1
[0, 1]
R
1
DBS – The Entity Relationship Model
E2
49 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Chen notation vs [min,max] notation
1:1 relationship type
E1
[0, 1]
1
[0, 1]
R
1
E2
1:N relationship type
E1
Dr. Rudra Pratap Deb Nath
[0, *]
1
[0, 1]
R
N
DBS – The Entity Relationship Model
E2
49 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Chen notation vs [min,max] notation
1:1 relationship type
E1
[0, 1]
1
[0, 1]
R
1
E2
1:N relationship type
E1
[0, *]
1
[0, 1]
R
N
E2
N:M relationship type
E1
Dr. Rudra Pratap Deb Nath
[0, *]
N
[0, *]
R
M
DBS – The Entity Relationship Model
E2
49 / 111
DBS – The Entity Relationship Model
Additional concepts
Outline
1
Database design
2
Basic concepts
3
Characteristics of relationship types
4
Additional concepts
Weak entity types
The isa relationship type
5
Alternative notations
6
Mapping basic concepts to relations
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
49 / 111
DBS – The Entity Relationship Model
Additional concepts
Weak entity types
Weak entity types
vintage
N
belongs to
1
year
wine
name
residual
sweetness
color
The existence of a weak entity depends on the existence of a strong
entity (aka. identifying or owning entity) associated by an identifying
relationship.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
50 / 111
DBS – The Entity Relationship Model
Additional concepts
Weak entity types
Weak entity types
vintage
N
belongs to
1
year
wine
name
residual
sweetness
color
Total participation of the weak entity type.
Only in combination with 1:N (N:1) (or rarely also 1:1) relationship
types
The strong entity type is always on the “1”-side
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
50 / 111
DBS – The Entity Relationship Model
Additional concepts
Weak entity types
Weak entity types
vintage
N
belongs to
1
year
wine
name
residual
sweetness
color
Weak entities are uniquely identifiable in combination with the
corresponding strong entity’s key.
The weak entity type’s key attributes are marked by underlining with
a dashed line (partial key, discriminator).
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
50 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
The isa relationship type
Specialization and generalization is expressed by the isa relationship
type (inheritance).
production
sparkling
wine
Dr. Rudra Pratap Deb Nath
name
ISA
wine
DBS – The Entity Relationship Model
color
51 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Characteristics
production
sparkling
wine
name
ISA
wine
color
Each sparkling wine entity is associated with exactly one wine entity
sparkling wine entities are identified by the functional isa relationship
Not every wine is also a sparkling wine
Attributes of entity type wine are inherited by entity type sparkling wine
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
52 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Characteristics
w1
w1
w2
w4
w2
w3
w4
w5
sparkling wine
w6
wine
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
53 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Cardinality
production
sparkling
wine
name
ISA
wine
color
The cardinalities are always
isa(E1 [1, 1], E2 [0, 1])
Each entity of entity type E1 (sparkling wine) participates exactly
once, entities of entity type E2 (wine) participate at most once.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
54 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
University example (overlapping specialization)
name
studID
universityMember
ISA
ISA
student
employee
ISA
empID
ISA
rank
department
Dr. Rudra Pratap Deb Nath
assistant
DBS – The Entity Relationship Model
professor
office
55 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Special characteristics
Overlapping specialization
An entity may belong to multiple specialized entity sets.
→ separate ISA symbols are used
Disjoint specialization
An entity may belong to at most one specialized entity set.
→ arrows to a shared ISA symbol in the diagram
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
56 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
University example
name
universityMember
ISA
studID
employee
student
empID
ISA
department
Dr. Rudra Pratap Deb Nath
assistant
DBS – The Entity Relationship Model
rank
professor
office
57 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Attributes and relationship types
Lower-level entity types inherit
attributes of the higher-level entity type
participation in relationship types of the higher-level entity type
Lower-level entity types can
have attributes
participate in relationship types that the higher-level entity type does
not participate in
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
58 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Participation constraints
Total generalization/specialization
Each higher-level entity must belong to a lower-level entity type.
Notation: double line
Partial generalization/specialization (default)
Each higher-level entity can (may or may not) belong to a lower-level
entity type.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
59 / 111
DBS – The Entity Relationship Model
Alternative notations
Outline
1
Database design
2
Basic concepts
3
Characteristics of relationship types
4
Additional concepts
5
Alternative notations
6
Mapping basic concepts to relations
7
Mapping additional concepts to relations
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
59 / 111
DBS – The Entity Relationship Model
Alternative notations
Alternative notations
http://en.wikipedia.org/wiki/Entity-relationship_model
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
60 / 111
DBS – The Entity Relationship Model
Alternative notations
Alternative notations
http://en.wikipedia.org/wiki/Entity-relationship_model
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
60 / 111
DBS – The Entity Relationship Model
Summary
Entity relationship diagrams (ERDs) describe the conceptual schema
of a database
There is also an extended ER model
Basic ER concepts (Entity types, relationship types, attributes)
Degree of relationship types
Cardinalities (Chen, [min,max], total/partial participation)
Weak entity types
isa relationship type
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
64 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Outline I
1
Database design
Steps of database design
Example design
2
Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
3
Characteristics of relationship types
Degree
Chen notation (cardinality ratio)
Participation constraint
Chen notation (cardinality ratios) for nary relationship types
[min, max] notation (cardinality limits)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
64 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Outline II
4
Additional concepts
Weak entity types
The isa relationship type
5
Alternative notations
6
Mapping basic concepts to relations
Entity types
Relationship types
7
Mapping additional concepts to relations
Weak entity types
Recursive relationship types
N-ary relationship types
Special attributes
Generalization
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
65 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Outline III
8
Example schemas
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
66 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Design notes
Entities correspond to nouns, relationships to verbs.
Each statement in the requirement specification should be reflected
somewhere in the ER schema.
Each ER diagram (ERD) should be located somewhere in the
requirement specification.
Conceptual design often reveals inconsistencies and ambiguities in the
requirement specification, which must be first resolved.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
66 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Entity types
University schema with cardinality ratios
department
empID
assistant
name
N
worksFor
grade
name
empID
semester
1
grades
N
1
professor
student
1
M
studID
N
name
rank
office
takes
teaches
M
M
N
course
requires
How to create
relations representing
all information of this
ER diagram?
ects
courseID
N
title
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
66 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Entity types
Entity types
student
{[ studID: integer, name: string, semester: integer ]}
course
{[ courseID: integer, title: string, ects: integer ]}
professor
{[ empID: integer, name: string, rank: string, office: integer ]}
assistant
{[ empID: integer, name: string, department: string ]}
Basic approach
For each entity type → relation
Name of the entity type → name of the relation
Attributes of the entity type → Attributes of the relation
Primary key of the entity type → Primary key of the relation
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
67 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Entity types
Entity types
student
{[ studID: integer, name: string, semester: integer ]}
course
{[ courseID: integer, title: string, ects: integer ]}
professor
{[ empID: integer, name: string, rank: string, office: integer ]}
assistant
{[ empID: integer, name: string, department: string ]}
Notation of relational schemas
student (studID: integer, name: string, semester: integer)
student: {[ studID: integer, name: string, semester: integer ]}
We do not care about the order of attributes in this context!
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
67 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Entity types
Entity types
student
{[ studID: integer, name: string, semester: integer ]}
course
{[ courseID: integer, title: string, ects: integer ]}
professor
{[ empID: integer, name: string, rank: string, office: integer ]}
assistant
{[ empID: integer, name: string, department: string ]}
Notation of relational schemas
student (studID, name, semester)
student: {[ studID, name, semester ]}
And for the moment we also do not care about attribute domains.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
67 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of N:M relationship types
semester
studID
ects
student
N
takes
M
course
name
courseID
title
How to map this information to relations?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of N:M relationship types
semester
studID
ects
student
N
takes
M
course
name
courseID
title
Basic approach
New relation with all attributes of the relationship type
Add the primary key attributes of all involved entity types
Primary keys of involved entity types together become the key of the
new relation
takes: {[ studID → student, courseID → course ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of N:M relationship types
semester
studID
ects
student
N
takes
M
course
name
courseID
title
Basic approach
New relation with all attributes of the relationship type
Add the primary key attributes of all involved entity types
Primary keys of involved entity types together become the key of the
new relation
Key attributes “imported” from involved entity types (relations) are called
foreign keys.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of N:M relationship types
student
studID ...
26120 ...
27550 ...
...
...
semester
studID
student
takes
studID courseID
26120
5001
27550
5001
27550
4052
28106
5041
28106
5052
28106
5216
28106
5259
29120
5001
29120
5041
29120
5049
N
takes
course
courseID
5001
4052
...
...
...
...
...
ects
M
course
name
Dr. Rudra Pratap Deb Nath
courseID
title
DBS – The Entity Relationship Model
4th Semester 2022
69 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of N:M relationship types in general
AE1,1 ...
AE1,k(1)
...
E1
AR,1 ...
R
AE2,1
AR,k(R)
AEn,1 ...
AE2,k(2)
AEn,k(n)
E2
...
...
En
...
R: {[ AE1,1 , ..., AE1,k(1) , AE2,1 , ..., AE2,k(2) , ..., AEn,1 , ..., AEn,k(n) , AR,1 , ..., AR2,k(R) ]}
key of E1
Dr. Rudra Pratap Deb Nath
key of E2
key of En
DBS – The Entity Relationship Model
attributes of R
4th Semester 2022
70 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of 1:N relationship types
name
empID
rank
ects
professor
1
teaches
N
course
courseID
title
office
Is this different from N:M relationship types?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
71 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:N relationship types
name
empID
rank
ects
professor
1
teaches
N
course
courseID
title
office
New relation with all attributes of the relationship type
Add primary key attributes of all involved entity types
Initially!
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:N relationship types
name
empID
rank
ects
professor
1
teaches
N
course
courseID
title
office
New relation with all attributes of the relationship type
Add primary key attributes of all involved entity types
Primary key . . .
Initially!
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:N relationship types
name
empID
rank
ects
professor
1
teaches
N
course
courseID
title
office
New relation with all attributes of the relationship type
Add primary key attributes of all involved entity types
Primary key of the “N”-side becomes the key in the new relation
Initially!
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of 1:N relationship types
Initially
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of 1:N relationship types
Initially
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor}
Improvement by merging
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
taughtBy is a foreign key and references the primary key of relation
professor.
Values of taughtBy correspond to values of empID in relation professor.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of 1:N relationship types
Initially
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor}
Improvement by merging
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
taughtBy is a foreign key and references the primary key of relation
professor.
Values of taughtBy correspond to values of empID in relation professor.
Relations with the same key can be combined. . .
but only these and no others!
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Mapping of 1:N relationship types
Initially
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
teaches: {[ courseID → course, empID → professor}
Improvement by merging
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
taughtBy is a foreign key and references the primary key of relation
professor.
Values of taughtBy correspond to values of empID in relation professor.
If the participation is not total, merging requires null values for the
foreign key. In such cases, it might be preferable for some applications to
have a separate relation.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Professor and course
empID
professor
name
rank office
2125 Socrates C4
2126
Russel
C4
2127 Kopernikus C3
2133
Popper
C3
2134 Augustinus C3
2136
Curie
C4
2137
Kant
C4
name
empID
226
232
310
52
309
36
7
office
professor
Dr. Rudra Pratap Deb Nath
course
title
courseID
5001
5041
5043
5049
4052
5052
5216
5259
5022
4630
DBS
Robotics
Software Engineering
Ethics
Logic
Theory of Science
Bioethics
Chemistry
Belief and Knowledge
Physics
title
rank
1
ects taughtBy
teaches
N
DBS – The Entity Relationship Model
course
4
4
3
2
4
3
2
2
2
4
2137
2125
2126
2125
2125
2126
2126
2133
2134
2137
ects
courseID
4th Semester 2022
74 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Attention: this does not work
professor
name
rank
empID
2125
2125
2125
...
2134
2136
...
Socrates
Socrates
Socrates
...
Augustinus
Curie
...
name
empID
C4
C4
C4
...
C3
C4
...
office
professor
Dr. Rudra Pratap Deb Nath
office
teaches
226
226
226
...
309
36
...
5041
5049
4052
...
5022
??
...
courseID
5001
5041
5043
5049
4052
5052
5216
5259
5022
4630
teaches
N
DBS – The Entity Relationship Model
ects
DBS
Robotics
Software Engineering
Ethics
Logic
Theory of Science
Bioethics
Chemistry
Belief and Knowledge
Physics
title
rank
1
course
title
course
4
4
3
2
4
3
2
2
2
4
ects
courseID
4th Semester 2022
75 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why can/will there be problems?
empID
2125
2125
2125
...
2134
2136
...
professor
name
rank
Socrates
Socrates
Socrates
...
Augustinus
Curie
...
C4
C4
C4
...
C3
C4
...
office
teaches
226
226
226
...
309
36
...
5041
5049
4052
...
5022
??
...
courseID
5001
5041
5043
5049
4052
5052
5216
5259
5022
4630
course
title
DBS
Robotics
Software Engineering
Ethics
Logic
Theory of Science
Bioethics
Chemistry
Belief and Knowledge
Physics
ects
4
4
3
2
4
3
2
2
2
4
Update anomaly: What happens when Socrates moves?
Deletion anomaly: What happens if “Belief and Knowledge” is no
longer taught?
Insert anomaly: Curie is new and does not yet teach any lectures
.Dr.. .Rudra Pratap Deb Nath
4th Semester 2022
DBS – The Entity Relationship Model
76 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Summary: N:1 relationship types
located in
producer
vineyard
address
area
name
country
region
How to map this ERD to relations?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
77 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Summary: N:1 relationship types
located in
producer
vineyard
address
area
name
country
region
How to map this ERD to relations?
producer: {[ vineyard, address, locatedIn → area ]}
area: {[ name, country, region ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
77 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:1 relationship types
license
licenseID
producer
owns
amount
vineyard
address
Is this different from 1:N relationship types?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
78 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:1 relationship types
license
licenseID
producer
owns
amount
vineyard
address
New relation with all attributes of the relationship type
Add primary key attributes of all involved entity types
Primary key of any of the involved entity types can become the key in
the new relation
Initially!
license: {[ licenseID, amount ]}
producer: {[ vineyard, address ]}
owns: {[ licenseID → license, vineyard → producer ]} or
owns: {[ licenseID → license, vineyard → producer ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
78 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:1 relationship types
Initially
license: {[ licenseID, amount ]}
producer: {[ vineyard, address ]}
owns: {[ licenseID → license, vineyard → producer ]} or
owns: {[ licenseID → license, vineyard → producer ]}
Improvement by merging
license: {[ licenseID, amount, ownedBy → producer ]}
producer: {[ vineyard, address ]}
or
license: {[ licenseID, amount ]}
producer: {[ vineyard, address, ownsLicense → license ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
79 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1:1 relationship types
Initially
license: {[ licenseID, amount ]}
producer: {[ vineyard, address ]}
owns: {[ licenseID → license, vineyard → producer ]} or
owns: {[ licenseID → license, vineyard → producer ]}
Improvement by merging
license: {[ licenseID, amount, ownedBy → producer ]}
producer: {[ vineyard, address ]}
or
license: {[ licenseID, amount ]}
producer: {[ vineyard, address, ownsLicense → license ]}
It is best to extend a relation of an entity type with total participation.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
79 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
amount
producer vineyard
Rotkäppchen
Weingut Müller
Dr. Rudra Pratap Deb Nath
producer
owns
vineyard
address
Freiberg
Dagstuhl
licenseID
42-007
42-009
DBS – The Entity Relationship Model
address
amount
10.000
250
4th Semester 2022
80 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
producer vineyard
Rotkäppchen
Weingut Müller
vineyard
address
Freiberg
Dagstuhl
licenseID
42-007
42-009
address
amount
10.000
250
Only correct in case of total participation ([1,1]) of both involved entity
types
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
80 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
vineyard
address
Producers without licenses require null values
producer vineyard
Rotkäppchen
Weingut Müller
Dr. Rudra Pratap Deb Nath
address
Freiberg
Dagstuhl
licenseID
42-007
⊥
DBS – The Entity Relationship Model
amount
10.000
⊥
4th Semester 2022
81 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
vineyard
address
Producers without licenses require null values
producer vineyard
Rotkäppchen
Weingut Müller
address
Freiberg
Dagstuhl
licenseID
42-007
⊥
amount
10.000
⊥
Possible in case of partial participation ([0,1]) of one involved entity type, total
participation of the other one
→ leads to null values
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
81 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
vineyard
address
Free licenses lead to more null values
producer vineyard
Rotkäppchen
Weingut Müller
⊥
Dr. Rudra Pratap Deb Nath
address
Freiberg
Dagstuhl
⊥
licenseID
42-007
⊥
42-003
DBS – The Entity Relationship Model
amount
10.000
⊥
100.000
4th Semester 2022
82 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
vineyard
address
Free licenses lead to more null values
producer vineyard
Rotkäppchen
Weingut Müller
⊥
address
Freiberg
Dagstuhl
⊥
licenseID
42-007
⊥
42-003
amount
10.000
⊥
100.000
Partial participation of both involved entity types
→ leads to null values in all attributes
→ difficult to determine a primary key, waste of memory
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
82 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Why not a single relation?
license
licenseID
producer
owns
amount
vineyard
address
Free licenses lead to more null values
producer vineyard
Rotkäppchen
Weingut Müller
⊥
address
Freiberg
Dagstuhl
⊥
licenseID
42-007
⊥
42-003
amount
10.000
⊥
100.000
In general: no merging into a single relation!
Standard approach: 2 relations (some null values are tolerable in most
applications)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
82 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Summary: mapping relationship types to relations
M:N relationship type
New relation with relationship type’s attributes
Add attributes referencing the primary keys of the involved entity type
relations
Primary key: set of foreign keys
1:N relationship type
Add information to the entity type relation of the “N”-side:
Add foreign key referencing the primary key of the “1”-side entity type
relation
Add attributes of the relationship type
1:1 relationship type
Add information to one of the involved entity type relations:
Add foreign key referencing the primary key of the other entity type
relation
Add attributes of the relationship type
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
83 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Foreign keys
A foreign key is an attribute (or a combination of attributes) of a relation
that references the primary key (or candidate key) of another relation.
Example
course: {[ courseID, title, ects, taughtBy ]}
professor: {[ empID, name, rank, office ]}
taughtBy is a foreign key referencing relation professor
Notation
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
84 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Foreign keys
A foreign key is an attribute (or a combination of attributes) of a relation
that references the primary key (or candidate key) of another relation.
Notation
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
Alternative notation
course: {[ courseID, title, ects, taughtBy ]}
professor: {[ empID, name, rank, office ]}
Foreign key: course.taughtBy → professor.empID
Notation for composite keys: { R.A1 , R.A2 } → { S.B1 , S.B2 }
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
84 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Outline I
1
Database design
Steps of database design
Example design
2
Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
3
Characteristics of relationship types
Degree
Chen notation (cardinality ratio)
Participation constraint
Chen notation (cardinality ratios) for nary relationship types
[min, max] notation (cardinality limits)
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
84 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Outline II
4
Additional concepts
Weak entity types
The isa relationship type
5
Alternative notations
6
Mapping basic concepts to relations
Entity types
Relationship types
7
Mapping additional concepts to relations
Weak entity types
Recursive relationship types
N-ary relationship types
Special attributes
Generalization
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
85 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Outline III
8
Example schemas
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
86 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Weak entity types
vintage
residual
Sweetness
belongsTo
N
year
1
wine
name
color
Entities of a weak entity type are
existentially dependent on a strong entity type
uniquely identifiable in combination with the strong entity type’s key
How to map weak entity types to relations?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
86 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Weak entity types
vintage
residual
Sweetness
N
belongsTo
year
1
wine
name
color
Mapping the identifying relationship type
New relation with all attributes of the relationship type
Add primary key attributes of all involved entity types
Foreign key of the “N”-side becomes the key in the new relation
Initially!
wine: {[ color, name ]}
vintage: {[ name → wine, year, residualSweetness ]}
belongsTo: {[ name → wine, year → vintage ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
87 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Weak entity types
vintage
residual
Sweetness
belongsTo
N
year
1
name
wine
color
Weak entity types and their identifying relationship types can always be
merged.
wine: {[ color, name ]}
vintage: {[ name → wine, year, residualSweetness ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
88 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
A more complex example
examPart
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
M
title
empID
ects
course
exam:
comprises:
M
professor
rank
office
conducts:
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
A more complex example
examPart
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
M
title
empID
ects
course
exam: {[ studID → student, examPart, grade ]}
comprises:
M
professor
rank
office
conducts:
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
A more complex example
examPart
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
empID
ects
M
M
title
course
professor
exam: {[ studID → student, examPart, grade ]}
comprises: {[ studID, examPart, courseID → course ]} with
rank
office
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
conducts:
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
A more complex example
examPart
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
empID
ects
M
M
title
course
professor
exam: {[ studID → student, examPart, grade ]}
comprises: {[ studID, examPart, courseID → course ]} with
rank
office
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
conducts: {[ studID, examPart, empID → professor ]} with
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Only one examiner per exam: whatexamPart
changes?
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
empID
ects
1
M
title
course
professor
exam: {[ studID → student, examPart, grade ]}
comprises: {[ studID, examPart, courseID → course ]} with
rank
office
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
conducts: {[ studID, examPart, empID → professor ]} with
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Only one examiner per exam: whatexamPart
changes?
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
empID
ects
1
M
title
course
professor
exam: {[ studID → student, examPart, grade ]}
comprises: {[ studID, examPart, courseID → course ]} with
rank
office
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
conducts: {[ studID, examPart, empID → professor ]} with
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
Only one examiner per exam: whatexamPart
changes?
semester
student
1
takes
N
exam
grade
N
name
N
studID
conducts
comprises
courseID
empID
ects
1
M
title
professor
course
rank
office
exam: {[studID → student, examPart, grade, examiner → professor ]}
comprises: {[studID, examPart, courseID → course ]} with
Foreign key: {studID, examP art} → {exam.studID, exam.examP art}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Recursive relationship types
Recursive relationship types
name
from
area
border
to
region
Mapping just like standard N:M relationship types and renaming of foreign
keys
area: {[ name, region ]}
border: {[ from → area, to → area ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
91 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Recursive relationship types
Recursive functional relationship types
name
mentor
critic
organization
studentOf
student
Mapping just like standard 1:N relationship types and merging
critic: {[ name, organization, mentor → critic ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
92 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
N-ary relationship types
sideOrder
description
WName
dish
wine
recommends
residual
Sweetness
critic
name
color
year
organization
Entity types:
All participating entity types are mapped according to the standard rules.
critic: {[ name, organization ]}
dish: {[ description, sideOrder ]}
wine: {[ color, WName, year, residualSweetness ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
93 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
N-ary relationship types
sideOrder
description
WName
dish
wine
recommends
residual
Sweetness
critic
name
color
year
organization
N-ary relationship types (N:M:P)
recommends: {[ WName → wine, description → dish, name → critic ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
93 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
N:M:1 relationship type
empID
student
name
office
1
rank
semester
studID
professor
N
grades
name
M
ects
course
courseID
title
grade
Relations
student: {[ studID, name, semester ]}
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
grades:
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
94 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
N:M:1 relationship type
empID
student
name
office
1
rank
semester
studID
professor
N
grades
name
M
ects
course
courseID
title
grade
Relations
student: {[ studID, name, semester ]}
course: {[ courseID, title, ects ]}
professor: {[ empID, name, rank, office ]}
grades: {[ studID → student, courseID → course, empID → professor, grade ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
94 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Multi-valued attributes
PID
person
phone
number
name
Create a separate relation for each multi-valued attribute
Relations
person: {[ PID, name ]}
phoneNumber: {[ PID → person, number ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
95 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Composite attributes
street
PID
person
address
name
city
Include the component attributes in the relation
Relation
person: {[ PID, name, street, city ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
96 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Derived attributes
birthday
PID
person
name
age
Ignored during mapping to relations, can be added later by using views.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
97 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Overview of the steps
1
Regular entity type
Create a relation, consider special attribute types
2
Weak entity type
Create a relation
3
1:1 binary relationship type
Extend a relation with foreign key
4
1:N binary relationship type
Extend a relation with foreign key
5
N:M relationship type
Create a relation
6
N-ary relationship type
Create a relation
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
98 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Relational modeling of generalization
department
assistant
employee
ISA
name
empID
professor
office
rank
The relational model does not support generalization and cannot express
inheritance.
→ Generalization is simulated.
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
99 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Relational modeling of generalization
department
assistant
employee
ISA
name
empID
professor
office
rank
How to map this information to relations?
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
99 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 1: main classes
department
assistant
employee
ISA
name
empID
professor
office
rank
A particular entity is mapped to a single tuple in a single relation (to its
main class).
employee: {[ empID, name ]}
professor: {[ empID, name, rank, office ]}
assistant: {[ empID, name, department ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
100 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 1: main classes
employee
empID
name
2123
2124
empID
2125
2126
2127
2128
empID
2150
2151
employee:
{[ empID, name ]}
P. Müller
A. Schmidt
professor
name
rank
Socrates
Russel
Kopernikus
Curie
C4
C3
C3
C4
office
226
232
310
36
assistant
name
department
C. Meyer
B. Fischer
Dr. Rudra Pratap Deb Nath
DBS
Physics
professor:
{[ empID, name, rank, office ]}
assistant:
{[ empID, name, department ]}
DBS – The Entity Relationship Model
4th Semester 2022
101 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 2: partitioning
department
assistant
employee
ISA
name
empID
professor
office
rank
Parts of a particular entity are mapped to multiple relations, the key is
duplicated.
employee: {[ empID, name ]}
professor: {[ empID → employee, rank, office ]}
assistant: {[ empID → employee, department ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
102 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 2: partitioning
employee
empID
name
2123
2124
2125
...
2150
2151
P. Müller
A. Schmidt
Socrates
...
C. Meyer
B. Fischer
professor
empID rank office
2125
...
C4
...
226
...
assistant
empID department
2150
2151
DBS
Physics
Dr. Rudra Pratap Deb Nath
employee:
{[ empID, name ]}
professor:
{[ empID → employee, rank, office ]}
assistant:
{[ empID → employee, department ]}
DBS – The Entity Relationship Model
4th Semester 2022
103 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 3: full redundancy
department
assistant
employee
ISA
name
empID
professor
office
rank
A particular entity is stored redundantly in the relations with all its
inherited attributes.
employee: {[ empID, name ]}
professor: {[ empID, name, rank, office ]}
assistant: {[ empID, name, department ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
104 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 3: full redundancy
employee
empID
name
2123
2124
2125
...
2150
2151
empID
2125
...
empID
2150
2151
P. Müller
A. Schmidt
Socrates
...
C. Meyer
B. Fischer
professor
name
rank
Socrates
...
C4
...
employee:
{[ empID, name ]}
office
226
...
assistant
name
department
C. Meyer
B. Fischer
Dr. Rudra Pratap Deb Nath
DBS
Physics
professor:
{[ empID, name, rank, office ]}
assistant:
{[ empID, name, department ]}
DBS – The Entity Relationship Model
4th Semester 2022
105 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 4: single relation
department
assistant
employee
ISA
name
empID
professor
office
rank
All entities are stored in a single relation. An additional attribute encodes
the membership in a particular entity type.
employee: {[ empID, name, type, rank, office, department ]}
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
106 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 4: single relation
employee: {[ empID, name, type, rank, office, department ]}
employee
type
rank
empID
name
2123
2124
2125
2126
2127
2128
2150
2151
P. Müller
A. Schmidt
Socrates
Russel
Kopernikus
Curie
C. Meyer
B. Fischer
Dr. Rudra Pratap Deb Nath
employee
employee
professor
professor
professor
professor
assistant
assistant
⊥
⊥
C4
C3
C3
C4
⊥
⊥
office
department
⊥
⊥
226
232
310
36
⊥
⊥
⊥
⊥
⊥
⊥
⊥
⊥
DBS
Physics
DBS – The Entity Relationship Model
4th Semester 2022
107 / 111
DBS – The Entity Relationship Model
Summary
Mapping ER diagrams to relations
Entity types
Binary relationship types
N-ary relationship types
Weak entity types
Recursive relationship types
Generalization
The “partitioning” alternative is preferred in most applications.
The discussed “mapping” rules aim for a minimum number of
relations, not necessarily minimum null values and redundancy!
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
108 / 111
DBS – The Entity Relationship Model
Appendix
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
109 / 111
DBS – The Entity Relationship Model
1
2
3
4
5
6
Database design
Steps of database design
Example design
Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
Characteristics of relationship types
Degree
Chen notation (cardinality ratio)
Participation constraint
Chen notation (cardinality ratios) for nary relationship types
[min, max] notation (cardinality limits)
Additional concepts
Weak entity types
The isa relationship type
Alternative
notations DBS – The Entity Relationship Model
Dr. Rudra Pratap Deb Nath
4th Semester 2022
Mapping basic concepts to relations
109 / 111
DBS – The Entity Relationship Model
Example schemas
color Chen notation
Wine schema with
name
country
name
grape type
description
area
N
side
order
region
percentage
made of
dish
located in
name
N
color
M
M
recommends
residual
sweetness
P
produces
wine
year
producer
vineyard
critic
address
owns
name
licenceID
organization
license
amount
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
110 / 111
DBS – The Entity Relationship Model
Example schemas
University schema with cardinality ratios
department
empID
assistant
name
N
worksFor
name
empID
semester
1
grades
N
1
instructor
student
1
M
studID
N
name
takes
teaches
M
M
N
course
requires
ects
courseID
N
title
Dr. Rudra Pratap Deb Nath
DBS – The Entity Relationship Model
4th Semester 2022
111 / 111
DBS-The Entity Relationship Model
Acknowledgement
Christian S. Jensen, Aalborg University
slides of Database System concept book
Dr. Rudra Pratap Deb Nath
DBS-The Entity Relatioship Model
4th Semester 2022
Download