Professional Documents
Culture Documents
• Introduction
• How to create an ERD
• Mapping from ERD to relational schema
Entity Relationship Model
Instructor: Vũ Tuyết Trinh
1 2
Objectives
• Upon completion of this lesson, students will be able to:
• Know what the entity relationship model is
• Know how to create an ERD from a real-world problem
• Transform from ERD into relational schema
1. Introduction
1. Introduction
2. Entity sets
3. Attributes
4. Key
5. Relationships
3 4
3 4
Relational Relational
Ideas ER design
Schema DBMS
5 6
5 6
1
student_id student
1.2. Entity sets 1.3. Attributes gender
7 8
7 8
first_name
last_name
9 10
9 10
full_name dob
11 12
11 12
2
1.5. Relationships 1.5. Relationships
• Relationships are connections among two or more entity sets.
• In ER diagrams, relationship types are displayed as diamond- dob
subject_id
shaped boxes, lecturer
student_id
• which are connected by straight lines to the rectangular boxes
representing the participating entity types.
• The relationship name is displayed in the diamond-shaped box. learn subject
student
credit
full_name
13 14
13 14
1.5. Relationships
• Type of relationships 1 1
shop manage manager
• 1–1
• 1–n
• n–m 1 n
class join student
• recursive
course
n
enroll
m
student
2. How to create an ERD
1. ERD process
role1 2. Example
subject condition
role2
15 16
15 16
17 18
17 18
3
2.2. An example
• We can draw this ER diagram
n m n m
student learn subject teach lecturer
3. Mapping from ERD to relational schema
name 1. Mapping process
2. Example
email phone
gender address name
semester
19 20
19 20
21 22
21 22
student_id
teacher_id
class_id name
class_id name n
1
1 1 name class join student
name class manage teacher dob
dob
faculty
faculty address
phone
23 24
23 24
4
3.1. Mapping process 3.1. Mapping process
• Mapping of n - m relationships • Mapping of multivalued attributes
• Create a new relation which has all prime-attributes of both entity sets • For each multivalued attribute A, create a new relation R including an
learn(subject_id, student_id) attribute corresponding to A, plus the primary key attribute K (as a
foreign key in R) of the corresponding entity set
• The primary key of R is the combination of A and K.
student_id • subject_lecturer(subject_id, lecturer)
subject_id name
n m lecturer
name subject learn student subject_id
dob
credit
address
subject
name credit
25 26
25 26
27 28
27 28
Quiz 1. Quiz 2.
Example
Quiz Quiz OX
1 Select OX Example Select
Number Type Quiz Number 2 Quiz Type
How many kinds of relationship have we just What is the type of attributes denoted by double ovals in
Question Question
studied? ERD?
A. 1 A. Multivalued attributes
B. 2 B. Atomic attributes
Example C. Composite attributes
C. 3 Example
D. Derived attributes
D. 4
Answer D
Answer A
1-1, 1-n, n-m, recursive
Feedback Feedback
29 30
29 30
5
Summary
• Introduction
• ERD in DB designing, and its components
• How to create an ERD
• discover entity sets, attributes and relationships among entity sets
• Mapping from ERD to relational schema
• transform from ERD into a set of tables
31
31