0% found this document useful (0 votes)
30 views34 pages

04 Entity Relationship Model

The document discusses the entity relationship model including how to create entity relationship diagrams and map them to relational schemas. It defines key concepts like entities, attributes, relationships and describes the process of identifying entities, attributes, and relationships from a scenario and drawing the ERD. It also explains how to map the ERD to relational tables and attributes.

Uploaded by

RoK Clone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views34 pages

04 Entity Relationship Model

The document discusses the entity relationship model including how to create entity relationship diagrams and map them to relational schemas. It defines key concepts like entities, attributes, relationships and describes the process of identifying entities, attributes, and relationships from a scenario and drawing the ERD. It also explains how to map the ERD to relational tables and attributes.

Uploaded by

RoK Clone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Lesson 4

Entity Relationship Model

2
Learning Map
Sequence Title
1 Introduction to Databases
2 Relational Databases
3 Relational Algebra

4 Structured Query Language – Part 1

5 Structured Query Language – Part 2


6 Constraints and Triggers
7 Entity Relationship Model
8 Functional Dependency
9 Normalization
10 Storage - Indexing
11 Query Processing
12 Transaction Management – Part 1
13 Transaction Management – Part 2

3
Outline
• Introduction
• How to create an ERD
• Mapping from ERD to relational schema

4
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

5
1. Introduction
1. Introduction
2. Entity sets
3. Attributes
4. Key
5. Relationships

6
1.1. Introduction
• Two approaches to DB designing
• Top - down: Entity Relationship model (ER)
• Bottom – up: Functional Dependencies and Normalization
• ER model is used in DB design

Relational Relational
Ideas ER design
Schema DBMS

7
1.1. Introduction
• The structure of data is represented graphically: ERD
• Three principal element types:
• Entity sets
• Attributes
• Relationships

8
1.2. Entity sets
• Entity
• is a thing in the real world with an independent existence.
• An entity may be an object with a physical existence (a particular
person, car, house, or employee) or it may be an object with a
conceptual existence (a company, a job, or a university course).
• Entity sets
• a collection of similar entities forms an entity set. student
• Weak entity type vs. strong entity type
• Weak entity type do not have key attributes of their own while strong
entity type do have a key attribute
• a weak entity can not be identified without an owner entity.
• In ERD, rectangular boxes represent for entity sets

9
student_id student
1.3. Attributes gender

• Attributes full_name dob


• Entity sets have associated attributes, which are properties of the
entities in that set.
• For instance, each entity "student" has some properties such as
student_id, first_name, last_name, dob, gender, address, and so on.
• In ERD, ovals represent for attributes
• Value domain of an attribute
• Each simple attribute of an entity type is associated with a value set (or
domain of values).
• For example: domain(gender) = {male, female}; domain(dob) = {date};
domain(last_name) = {char(30)}.

10
1.3. Attributes
• Some types of attributes city
• Simple/atomic attributes:
street state
Attributes that are not
divisible.
note
• Composite attributes: address
attributes can be divided
into smaller subparts, student_id
which represent more student
basic attributes with gender
independent meanings.
full_name dob

first_name
last_name

11
1.3. Attributes
• Some types of attributes
• Single-valued attributes: have a
single value for a particular entity
lecturer
• Multi-valued attributes: can have
different numbers of values
subject_id subject
credit

name

12
1.3. Attributes
• Some types of attributes
• Stored attributes vs. Derived dob
attributes: age attribute is called a student_id
derived attribute and is said to be
derivable from the dob attribute,
which is called a stored attribute. student

age
full_name

13
1.4. Key
• One or more attributes whose values are distinct for each
individual entity in the entity set. Such an attribute is called a
key attribute, and its values can be used to identify each entity
uniquely.
• Each entity can have some keys. We choose one of them to be
primary key.
• In ER diagrammatic notation, each key attribute has its name
underlined inside the oval.
student_id student
gender

full_name dob

14
1.5. Relationships
• Relationships are connections among two or more entity sets.
• In ER diagrams, relationship types are displayed as diamond-
shaped boxes,
• 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.

student learn subject

15
1.5. Relationships

dob
subject_id
student_id lecturer

student learn subject

credit
full_name
age result name

16
1.5. Relationships
• Type of relationships 1 1
shop manage manager
• 1–1
• 1–n
• n–m 1 n
class join student
• recursive

n m
course enroll student

role1
subject condition

role2
17
2. How to create an ERD
1. ERD process
2. Example

18
2.1. ERD process
• Step 1: Identify all entity sets
• Notice concepts, nouns
• Step 2: Identify all relationships among entity sets
• Notice verbs
• Type and degree of relationships

19
2.2. An example
• Read carefully the following scenario:
• The information about students includes student identification (uniquely
identify each student), name, gender, date of birth and address.
• During the education time at school, students must study a lot of
subjects. A subject can be learnt by students. A subject should be
contained information such as subject identification, name and credit.
• A lecturer can teach some subjects, and a subject can be taught by a
group of lecturers. The information about lecturers should include
lecturer identification, name, phone, email.
• Students learn subjects at some semester, and their results should be
stored.

20
2.2. An example
• We can draw this ER diagram

subject_id lecturer_id name


result credit
student_id
dob

n m n m
student learn subject teach lecturer

name

email phone
gender address name
semester

21
3. Mapping from ERD to relational schema
1. Mapping process
2. Example

22
3.1. Mapping process
• Mapping of strong entity sets
• For each entity set, create a relation that includes all the simple
attributes of that entity set.
• PK of entity set becomes PK of the relation
class(class_id, name, faculty)
teacher(teacher_id, name, dob, phone)
teacher_id

class_id name
1 1
name class manage teacher dob
faculty
phone

23
3.1. Mapping process
• Mapping of weak entity sets
• For each entity set, create a relation that includes all the simple
attributes of that entity set.
• PK of strong entity set should be included in PK of the relation
dependent(emp_id, name, dob, sex)

emp_id name
1 n
name employee dependents_of dependent dob
address
sex sex

24
3.1. Mapping process
• Mapping of 1 - 1 relationships
• Create a new relation which has all prime-attributes of both entity sets
manage(class_id, teacher_id)
• Use foreign key
class(class_id, name, faculty, teacher_id)

teacher_id

class_id name
1 1
name class manage teacher dob
faculty
phone

25
3.1. Mapping process
• Mapping of 1 - n relationships
• Create a new relation which has all prime-attributes of both entity sets
join(class_id, student_id)
• Use foreign key
student(student_id, name, dob, address, class_id)

student_id

class_id name
1 n
name class join student dob
faculty
address

26
3.1. Mapping process
• Mapping of n - m relationships
• Create a new relation which has all prime-attributes of both entity sets
learn(subject_id, student_id)

student_id

subject_id name
n m
name subject learn student dob
credit
address

27
3.1. Mapping process
• Mapping of multivalued attributes
• For each multivalued attribute A, create a new relation R including an
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.
• subject_lecturer(subject_id, lecturer)

lecturer
subject_id

subject
name credit

28
3.2. Example
• student(student_id, name, gender, dob, address)
• subject(subject_id, name, credit)
• lecturer(lecturer_id, name, phone, email)
• learn(student_id, subject_id, semester, result)
• teach(lecturer_id, subject_id)

29
Remark
• ERD: an approach to DB designing
• Entity sets, attributes, key, relationships
• How to create an ERD
• Mapping from ERD to relational schema

30
Quiz 1.
Example
Quiz Quiz OX
1 Select
Number Type

Question How many kinds of relationship have we just


studied?
A. 1
B. 2
Example
C. 3
D. 4
Answer D

Feedback 1-1, 1-n, n-m, recursive


31
Quiz 2.

OX Example Select
Quiz Number 2 Quiz Type

Question What is the type of attributes denoted by double ovals in


ERD?
A. Multivalued attributes
B. Atomic attributes
Example C. Composite attributes
D. Derived attributes

Answer A
Feedback
32
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

33
Thank you for
your attention!

34

You might also like