Entity Relationship Model in Databases
Entity Relationship Model in Databases
Database Systems
The Entity Relationship Model
University of Chittagong
rudra@[Link]
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 2021 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 2021 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 2021 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 2021 4 / 111
DBS – The Entity Relationship Model
Database design
Steps of database design
Conceptual schema
(ER schema)
Mapping onto a Semi-automatic
data model transformation
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 4 / 111
DBS – The Entity Relationship Model
Database design
Example design
[Link]
[Link]
[Link]
[Link]
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 2021 5 / 111
DBS – The Entity Relationship Model
Database design
Example design
Employees
Attributes: EmpNo, salary, rank
Salary
Type: decimal
EmpNo Length: (8,2)
Degree of availability: 10%
Type: char
Uniqueness: no
Length: 9
Domain: 0. . . 999.999.99
Rank
Degree of availability: 100%
Uniqueness: true Type: String
Length: 4
Degree of availability: 100%
Uniqueness: no
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 6 / 111
DBS – The Entity Relationship Model
Database design
Example design
Relationship: “grades”
Participating objects
Instructor as examiner
Student as examinee
Course as topic
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 7 / 111
DBS – The Entity Relationship Model
Database design
Example design
name
offers takes
lecture courseID
title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 8 / 111
DBS – The Entity Relationship Model
Database design
Example design
[Link]
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 9 / 111
DBS – The Entity Relationship Model
Database design
Example design
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 2021 10 / 111
DBS – The Entity Relationship Model
Database design
Example design
Relational model
student (studID: integer, name: string)
takes (studID: integer, courseID: integer)
lecture (courseID: integer, title: string)
⇓ Mapping
Tables in a DB
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 11 / 111
DBS – The Entity Relationship Model
Database design
Example design
[Link]
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 12 / 111
DBS – The Entity Relationship Model
Database design
Example 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 2021 13 / 111
DBS – The Entity Relationship Model
Database design
Example 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 2021 13 / 111
DBS – The Entity Relationship Model
Basic concepts
Outline
1 Database design
2 Basic concepts
Example scenarios
Entity types
Attributes
Relationship types
4 Additional concepts
5 Alternative notations
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 13 / 111
DBS – The Entity Relationship Model
Basic concepts
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 14 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
Example scenarios
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 15 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
region
name
grapeType
description
area
side
Order percentage
madeOf
dish
locatedIn
name color
residual
year vineyard address
Sweetness
critic
owns
name licenseID
organization
license
amount
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 16 / 111
DBS – The Entity Relationship Model
Basic concepts
Example scenarios
name
worksFor
grades
name semester
name
teaches takes
ects
successor
requires course courseID
predecessor
title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 17 / 111
DBS – The Entity Relationship Model
Basic concepts
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 2021 18 / 111
DBS – The Entity Relationship Model
Basic concepts
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!
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 18 / 111
DBS – The Entity Relationship Model
Basic concepts
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!
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 18 / 111
DBS – The Entity Relationship Model
Basic concepts
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!
wine
Attributes
name color
year
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 19 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
phone phone
person number
person number
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 20 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
street
city
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 21 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Attributes
birthday
person
age
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 22 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Keys
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 23 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
name color
year
wineID
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 24 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
name color
year
wineID
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 24 / 111
DBS – The Entity Relationship Model
Basic concepts
Attributes
Primary keys
name color
year
wineID
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 24 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 25 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
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 2021 25 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
R ⊆ E1 × E2 × · · · × En
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 26 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
wife
person marriedTo
husband
sequel
movie sequelOf
original
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 27 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
percentage
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 28 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
1. Entity
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
2. Relationship
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
3. Attribute
takes
course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
course
ects title
courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
ects title
courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
ects title
courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Basic concepts
Relationship types
takes
3. Attribute
regular course
4. Primary key course
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Outline
1 Database design
2 Basic concepts
4 Additional concepts
5 Alternative notations
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 29 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
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 2021 30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
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 2021 30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
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 2021 30 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 31 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
d1 w1 d1 w1
d2 w2 d2 w2
c1 c2 c1 c2
critic critic
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 32 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
d1 w1
Reconstructible relationship
instances
d2 w2
d1 – c1 – w1
d1 – c2 – w2
d2 – c2 – w1
dish wine but also: d1 – c2 – w1
c1 c2
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 33 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Degree
d1 w1
c1 c2
critic
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 33 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
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 2021 34 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
R ⊆ E1 × E2
E1 R E2
N:1 N:M
E1 E2 E1 E2
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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)
7 E2 and R−1 : E2 →
1:1 relationship: R : E1 → 7 E1
1:N relationship: R−1 : E2 →
7 E1
N:1 relationship: R : E1 →
7 E2
also referred to as functional relationship.
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 36 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Chen notation (cardinality ratio)
Graphical notation
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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 2021 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
1:N relationship type with total participation of both involved entity types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 39 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 40 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 41 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 42 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
Summary cardinality ratios
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
N
En R E2
M
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
N
En R E2
M
Ek
professor
N 1
student supervises seminarTopic
grades
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)
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 46 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
[min2, max2]
E2
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)
[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 ∧ [Link] = 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)
[min2, max2]
E2
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)
[min2, max2]
E2
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)
[min2, max2]
E2
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 49 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 49 / 111
DBS – The Entity Relationship Model
Characteristics of relationship types
[min, max] notation (cardinality limits)
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 49 / 111
DBS – The Entity Relationship Model
Additional concepts
Outline
1 Database design
2 Basic concepts
4 Additional concepts
Weak entity types
The isa relationship type
5 Alternative notations
N 1
vintage belongs to wine
year
name
residual color
sweetness
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 50 / 111
DBS – The Entity Relationship Model
Additional concepts
Weak entity types
N 1
vintage belongs to wine
year
name
residual color
sweetness
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 50 / 111
DBS – The Entity Relationship Model
Additional concepts
Weak entity types
N 1
vintage belongs to wine
year
name
residual color
sweetness
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 50 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
production name
sparkling
ISA wine color
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 51 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Characteristics
production name
sparkling
ISA wine color
wine
Each sparkling wine entity is associated with exactly one wine entity
sparkling wine entities are identified by the functional isa relationship
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
w2 w4
w3
w4
sparkling wine
w5
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 name
sparkling
ISA wine color
wine
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 54 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
ISA ISA
ISA ISA
rank
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 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
ISA rank
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 57 / 111
DBS – The Entity Relationship Model
Additional concepts
The isa relationship type
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 59 / 111
DBS – The Entity Relationship Model
Alternative notations
Outline
1 Database design
2 Basic concepts
4 Additional concepts
5 Alternative notations
Alternative notations
[Link]
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 60 / 111
DBS – The Entity Relationship Model
Alternative notations
Alternative notations
[Link]
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 60 / 111
DBS – The Entity Relationship Model
Summary
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 2021 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 2021 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 2021 66 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Design notes
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 66 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Entity types
N name
worksFor
grade
name semester
1
grades N
How to create
empID professor 1
student studID relations representing
1 M N
all information of this
name
rank ER diagram?
office teaches takes
ects
N M
M
requires course courseID
N
title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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 2021 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 ]}
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 ]}
N M
studID student takes course courseID
name title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
N M
studID student takes course courseID
name 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
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
N M
studID student takes course courseID
name 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 2021 68 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
N M
studID student takes course courseID
name title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 69 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
AE1,k(1)
E1 ...
AR,1 ...
AR,k(R)
R
AE2,1 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) ]}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 70 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 71 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
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 2021 72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
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 2021 72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
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 2021 72 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Improvement by merging
course: {[ courseID, title, ects, taughtBy → professor ]}
professor: {[ empID, name, rank, office ]}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
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 2021 73 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 74 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
1 N
empID professor teaches course courseID
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 75 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 77 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 77 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 78 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
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 2021 79 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
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 2021 80 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 80 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 81 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
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 2021 81 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 82 / 111
DBS – The Entity Relationship Model
Mapping basic concepts to relations
Relationship types
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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 2021 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 ]}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 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 2021 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 2021 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 2021 86 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
residual
year name color
Sweetness
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 86 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
residual
year name color
Sweetness
residual
year name color
Sweetness
Weak entity types and their identifying relationship types can always be
merged.
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 88 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M M
exam: rank
comprises: office
conducts:
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M M
conducts:
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M M
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M M
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 89 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M 1
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M 1
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Weak entity types
1 N
student takes exam grade
N
name N
studID comprises conducts
empID
courseID ects
M 1
rank
office
exam: {[studID → student, examPart, grade, examiner → professor ]}
comprises: {[studID, examPart, courseID → course ]} with
Foreign key: {studID, examP art} → {[Link], [Link] art}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 90 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Recursive relationship types
name
from
area border
to
region
Mapping just like standard N:M relationship types and renaming of foreign
keys
name mentor
critic studentOf
organization student
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 92 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
recommends wine
residual
year
Sweetness
critic
name 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 2021 93 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
recommends wine
residual
year
Sweetness
critic
name organization
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 93 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
1 name
rank
semester ects
N M
studID student grades course courseID
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 2021 94 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
N-ary relationship types
1 name
rank
semester ects
N M
studID student grades course courseID
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 2021 94 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Multi-valued attributes
PID
phone
person number
name
Relations
person: {[ PID, name ]}
phoneNumber: {[ PID → person, number ]}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 95 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Composite attributes
street
PID
person address
name
city
Relation
person: {[ PID, name, street, city ]}
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 96 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Special attributes
Derived attributes
PID birthday
person
name age
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 97 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 98 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
department
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 2021 99 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
department
name empID
professor
office rank
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 99 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
name empID
professor
office rank
professor
empID name rank office
2125 Socrates C4 226 professor:
2126 Russel C3 232 {[ empID, name, rank, office ]}
2127 Kopernikus C3 310
2128 Curie C4 36
assistant
empID name department assistant:
2150 C. Meyer DBS {[ empID, name, department ]}
2151 B. Fischer Physics
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 101 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
Alternative 2: partitioning
department
name empID
professor
office rank
Alternative 2: partitioning
employee
empID name
2123 P. Müller
2124 A. Schmidt employee:
2125 Socrates {[ empID, name ]}
... ...
2150 C. Meyer
2151 B. Fischer
professor
empID rank office professor:
2125 C4 226 {[ empID → employee, rank, office ]}
... ... ...
assistant
empID department assistant:
2150 DBS {[ empID → employee, department ]}
2151 Physics
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 103 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
name empID
professor
office rank
department
name empID
professor
office rank
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 106 / 111
DBS – The Entity Relationship Model
Mapping additional concepts to relations
Generalization
employee
empID name type rank office department
2123 P. Müller employee ⊥ ⊥ ⊥
2124 A. Schmidt employee ⊥ ⊥ ⊥
2125 Socrates professor C4 226 ⊥
2126 Russel professor C3 232 ⊥
2127 Kopernikus professor C3 310 ⊥
2128 Curie professor C4 36 ⊥
2150 C. Meyer assistant ⊥ ⊥ DBS
2151 B. Fischer assistant ⊥ ⊥ Physics
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 107 / 111
DBS – The Entity Relationship Model
Summary
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 108 / 111
DBS – The Entity Relationship Model
Appendix
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 109 / 111
DBS – The Entity Relationship Model
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)
4 Additional concepts
Weak entity types
The isa relationship type
5 Alternative notations DBS – The Entity Relationship Model
Dr. Rudra Pratap Deb Nath 4th Semester 2021 109 / 111
6 Mapping basic concepts to relations
DBS – The Entity Relationship Model
Example schemas
region
name
grape type
description
N
area
side
order percentage
made of
dish
located in
name color
N
M
M
recommends wine produces producer
residual
P year vineyard address
sweetness
critic
owns
name licenceID
organization
license
amount
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 110 / 111
DBS – The Entity Relationship Model
Example schemas
N name
worksFor
name semester
1
grades N
empID 1 studID
instructor student
1 M N
name
teaches takes
ects
N M
M
requires course courseID
N
title
Dr. Rudra Pratap Deb Nath DBS – The Entity Relationship Model 4th Semester 2021 111 / 111
DBS-The Entity Relationship Model
Acknowledgement
Dr. Rudra Pratap Deb Nath DBS-The Entity Relatioship Model 4th Semester 2021