Professional Documents
Culture Documents
E R Diagram
E R Diagram
E R Diagram
FUNDAMENTAL OF ENTITY
RELATIONSHIP (ER)
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Objective
Identify the basic concept of Entity Relationship (ER) model, elements and notation of ER
model.
Identify entities, attributes and types of attribute.
Identify the relationship and cardinality constraint.
Identify the relation key and integrity constraint.
Define entity relationship diagram (ERD).
Identify the step to create an ERD diagram.
2.1.1 Introduction
ER Model is the constructs and conventions used to create a model of the user data.
The results are documented in an entity relationship diagram.
Entity relationship diagram is a diagram that depicts entity relationship model entities,
attributes and relations. It also displays connectivity and cardinality.
Relationship
Entity
2
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
The diagram above shows a car-purchasing model that involves the relationship between the factory, car and customer. Here,
we can see clearly that factory produces car and a customer purchases the car.
Entity: FACTORY, CAR & CUSTOMER.
Relationship: Produce & Purchased by.
publish written by
Books at E-Book bookstore are recorded. Information about publisher and the author will also be recorded
to make sure that the process of searching for the book is easier.
Transformed to ERD :
Step 1 :
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
Title
City Publisher_Cod
e
3
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Relationship One to Many (1:M): One publisher can publish many books while one book can only be published by
one publisher.
Step 2:
Book_Code
Author_No
Author_No
Langkah
Price Type
BOOK M N AUTHOR
Written by
Title Publisher_Cod
e Author_Name
Book_Code
Relationship Many to Many (M:N): One book can be written by many authors while one author can write
many books.
Complete ERD
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
City Publisher_Cod
e Title
Author_No
written by
Book_Code
Author_No
N
AUTHOR
Author_Name
4
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 2 :
Step 2 :
STUDENTBook_No BOOK AUTHOR
Book_No Author_ID
Book_Title
Transformed to ERD :
Transformed to ERD :
Relationship
Langkah Many
1 / Step 1 : to Many (M:N): One book may be written by a number of authors, whereas one
Langkah 1 / Step 1 :
author can write a number of books.
STUDENT M N BOOK
Book_No
borrow
Student_ID Student_ID Book_Title
ISDN
Student_Nam Book_No Book_Price
e
STUDENT M N BOOK
borrow
M
ISDN
Student_Name Book_No
Relationship Many to Many (M:N): One student can borrow a number
Book_Noof books, whereas each book can
be borrowed by many students.
written
Author_ID by
librarian
N
5 AUTHOR
Author_Name
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
The picture above show one department that have workers and each worker will responsible to one project.
Transformed to ERD :
Step 1 :
6
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
have handle
Complete ERD
DeptNo EmployeeNo
DeptNo
Name
Dept_Name Address
Relationship One to Many (M:N): One department can have many staff and one staff can only be in one
department.
7
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
EmployeeN
oNo ProjectN ProjectN
DeptNo o o
M 1
EMPLOYEE PROJECT
handle
Name
Deadlin
Address e
Relationship Many to One (M:N): One employee will handle one project and one project will be handle
by many employees.
ProjectN
DeptNo o
EmployeeN
DeptNo o
M
Name
Dept_Name Addres
s
handle
by
1
PROJECT
ProjectN
o
Deadlin
e
2.1.2 Elements of ER Model
8
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
A property or characteristic of
Attribute
an entity or relationship type.
Interaction of 2 entities
represented by a verb.
Relationship
9
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Entity
Relationship
Simple Attribute
Multivalue Attribute
Composite Attribute
Derived Attribute
2.2.1 Entity
10
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Definition
- Entity is a person, place, object, event or concept, which you want to store the
information in a database.
Characteristic of entities:
- Must have an attributes and unique key.
- Will become a Table in a database.
Classification of Entities:
Attribute :- Book_Code
Book_Title
Publisher_Code
Description
Type
Price 11
Book_Sample
Book_Cover
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
P01 P02
Access 2000 Processing Concepts of Database Management
M-G1 P-H1
Database Database
76.00 100.00
Yes No
Example 1
Example 1
Below is the example of attribute for E-Book database that you have create in Lab 2 (Question 1).
Below is the example of attribute for E-Book database that you have create in Lab 2 (Question 1).
Title
Publisher_Cod
e
Attributes for the entity BOOK are Book_Code, Type, Price, Title, and Publisher_Code.
Attributes for the entity BOOK are Book_Code, Type, Price, Title, and Publisher_Code.
Publisher_Name
Publisher_Cod
e
PUBLISHER
City
Author_No
AUTHOR
Author_Name
SIMPLE COMPOSITE
SIMPLE COMPOSITE
TYPES OF ATTRIBUTE
13
MULTIVALUED DERIVED
MULTIVALUED DERIVED
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Town
14
Address
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example: An address
comprises of city, postcode and
state.
15
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Ani ( Daugther)
Azman (Son) Azlee ( Son)
Grandchildren Grandchildren
The diagram above shows the hierarchy of En. Azhar's family. En. Azhar and Pn. Zainab have a
daughter, 2 sons and 4 grandchildren. The relationship within his family members can be viewed
clearly in this diagram. The relationship between Azhar and Azlee is that Azlee is Azhar's son.
2.3.1 Relationship
16
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example
Example
Manager_ID Branch_ID
1
1
MANAGER manag BRANCH
e
X Y
An employee (manager) can manage only one branch at one time and each branch only has one
An employee (manager) can manage only one branch at one time and each branch only has one
manager.
manager.
Example
Course_Code
Faculty_Name Faculty_Name
1 M
FACULTY offer COURSE
X Y
At university, one faculty offers many courses for students but one course is offered by one faculty
only.
17
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Definition: Possibly many X’s for each Y and maximum one Y for each X.
Example
Course_Cod
e
Student_ID
Course_Code
1
M
STUDENT register COURSE
Combination of (i) and (ii) :
Combination of (i) and (ii) :
X Y
Author_ID
Author_ID
ISDN
Every semester, a new student needs to register one course but one course is registered by many
students.
M N
AUTHOR
BOOK written by
Example
Authtor_ID
ISDN
A book may have more than one author and an author may write more than one book.
A book may have more than one author and an author may write more than one book.
1 M
BOOK written by AUTHOR
Conceptual Entity
Authtor_ID
Author_ID
Author_ID
ISDNISDN
MM N 1
BOOK written by AUTHOR
BOOK authoring AUTHOR
Both Primary Keys attributes from BOOK & AUTHOR (ISDN & Author_ID) will become the
Both Primary Keys attributes from BOOK & AUTHOR (ISDN & Author_ID) will become the
attributes for Composite Entity / Conceptual Entity (AUTHORING).
attributes for Composite Entity / Conceptual Entity (AUTHORING).
18
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Words that are written in capital letters and bold are ENTITY.
Bold words are Relationship.
19
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Attribute =
attribut
e
Example 1
Department have employee.
Solution:
Diagram A :
DeptNo EmployeeNo
DeptNo
Name
Dept_Name Address
Diagram B :
EmployeeNo
DeptN DeptNo
o
1 have 1
EMPLOYEE DEPARTMENT
Name
Combination of Diagram A & B:
Address Dept_Name
DeptNo EmployeeNo
DeptNo
20 Name
Dept_Name Address
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Diagram B :
Example 2
Employee handles project.
Solution:
EmployeeNo
Combination of Diagram A & B:ProjectN ProjectN
DeptNo
o o
1 1
EMPLOYEE PROJECT
handle
by
Name
Deadlin
Address e
EmployeeN
ProjectN o ProjectN
One to Many Relationship (1:M) – One PROJECT is handle
DeptNo by many EMPLOYEES while one
o o
EMPLOYEE can handle one PROJECT only.
PROJECT 1 M EMPLOYEE
handle
by
21
Name
Deadlin
e Address
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 3
Publisher publishes books.
Solution:
Diagram A :
EmployeeNo
ProjectN ProjectN
DeptNo
o o
PROJECT 1 M EMPLOYEE
handle
by
Name
Deadlin
e Address
Diagram B :
22
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
PUBLISHER 1 M BOOK
publish
City Publisher_Cod
e Title
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
City Publisher_Cod
e Title
Publisher_Name Type
OnePublisher_Cod Book_Cod
to Many Relationship (1:M) – One PUBLISHER can publish many BOOKS while one BOOK can be
Price
e
e one PUBLISHER.
published by
23
City Publisher_Cod
e Title
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 4 :
A lecturer may teach more than one subject and that subject may be taught by more than one lecturer.
Diagram A :
Diagram B
Combination A and B :
Many to Many Relationship (M:N) - A LECTURER may teach more than one SUBJECT, while each
SUBJECT may be taught by many LECTURERS.
24
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Subject_Cod
Lecturer_I e
Lecturer_ID D
1 M
LECTURER teach SUBJECT
Example 5 :
Students register course. Attribute for student are Student_ID and Student_Name, while the attribute for
course are Course_Code and Course_Name.
25
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Student_ID Course_Cod
e
1 1
STUDENT register COURSE
Student_Nam Course_Name
e
M 1
STUDENT register COURSE
Course_Name
M 1
STUDENT
Many to One Relationship (M : 1) – One STUDENT COURSE
register can register for one COURSE only and one
COURSE can be register by many STUDENTS.
26
Student_Nam
e Course_Name
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
27
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
- Relational key is a device that relates one entity with another entity in a relationship.
Example 1 :
Example 1 :
a) Below is the example of Candidate key referring to the table in E-Book database.
a) Below is the example of Candidate key referring to the table in E-Book database.
2.4.1 Types of Keys
Publisher_Name Type
Book_Cod
Publisher_Cod Price
Types of Keys Definition e
e
PUBLISHER 1 M BOOK
Candidate Key An attribute or group of attributes thatpublish
identifies a unique row in a relation. One
of the candidate keys is chosen to be the primary key.
Primary City
key Publisher_Cod
Any of the candidates that are selected to be the key or an attribute that uniquely Title
e
identifies each row in a relation.
An attribute in one table whose values must match the primary key in another
Foreign key table or whose value must be null.
PUBLISHER Attribute that act as a primary key in a related table.
PUBLISHER
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
Publisher_CodeNameCityF-B1Fajar
Composite Key BaktiMalaysiaM-G1McGraw
A primary key that consists HillUKP-H1Prentice
of more than one attribute, especially in (M:N) HallUKT-
relationship. H1ThompsonUS
H1ThompsonUS
BOOK
BOOK
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
Publisher_Code and Book_Code are Candidate Keys because both can uniquely identify a row in a relation.
Publisher_Code and Book_Code are Candidate Keys because both can uniquely identify a row in a relation.
28
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
b) Below is the example of Primary key referring to the table in E-Book database.
b) Below is the example of Primary key referring to the table in E-Book database.
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
City Publisher_Cod
e Title
PUBLISHER
PUBLISHER
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
H1ThompsonUS
H1ThompsonUS
BOOK
BOOK
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
Publisher_Code is a primary key for table PUBLISHER and Book_Code is a primay ker for table BOOK. Both
Publisher_Code is a primary key for table PUBLISHER and Book_Code is a primay ker for table BOOK. Both
primary keys can uniquely identify a row in a relation.
primary keys can uniquely identify a row in a relation.
29
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
c) Below is the example of foreign key referring to the table in E-Book database.
c) Below is the example of foreign key referring to the table in E-Book database.
Publisher_Name Type
Book_Cod
Publisher_Cod Price
e
e
City Publisher_Cod
e Title
PUBLISHER
PUBLISHER
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
H1ThompsonUS
H1ThompsonUS
BOOK
BOOK
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
Publisher_Code is a primary key for PUBLISHER table but it is a foreign key for BOOK table.
Publisher_Code is a primary key for PUBLISHER table but it is a foreign key for BOOK table.
For a table that have a M :1 or 1:M relationship, primary key for table (1) must be added in table (M) as a
For a table that have a M :1 or 1:M relationship, primary key for table (1) must be added in table (M) as a
foreign key. *
foreign key. *
30
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
d) Below is the example of Composite key referring to the table in E-Book database.
d) Below is the example of Composite key referring to the table in E-Book database.
Book_Code
Author_No
Author_No
Price Type
Title Publisher_Cod
e Author_Name
Book_Code
Book_Code
Author_No
Author_No
Price Type
Title Publisher_Cod
e Author_Name
Book_Code
BOOK_AUTHOR
Book_Code Author_No
P01 A006
P02 A001
P03 A002
P04 A003
P05 A004
P06 A008
P07 A005
Combination of Book_Code and Author_No can determine the books that are written by the author.
32
Many to Many Relationship (M:N) will create a new table that inherit primary key from both tables related
to it.
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
a) Entity Integrity
Requirement:
All entries are unique and no part of a primary key may be null.
Purpose:
Guarantees that each entity will have a unique identity and ensures that foreign key values
can properly refer to primary key values.
Example :
PUBLISHER
Publisher_Code Name City
F-B1 Fajar Bakti Malaysia
M-G1
Example: McGraw Hill UK
P-H1 Prentice Hall UK
T-H1 Student_ID is
Thompson
a primary key in US
Student table, so this field cannot have a null value.
Student_ID is a primary key in Student table, so this field cannot have a null value and all
entries are unique.
33
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
b) Referential Integrity
Referential integrity is a set of rules that prevents you from changing or deleting a record if
matching records exist in a related table.
Requirement
Contoh / Example :
Contoh Example
If /foreign key: exist in 1 table then the foreign key value must reference an existing primary
key value in a table to which it is related and it can be null.
PUBLISHER
PUBLISHER
Purpose
Publisher_CodeNameCityF-B1Fajar BaktiMalaysiaM-G1McGraw HillUKP-H1Prentice HallUKT-
Publisher_CodeNameCityF-B1Fajar
i) BaktiMalaysiaM-G1McGraw
Possibility for non-corresponding value, but impossible forHillUKP-H1Prentice
invalid entity. HallUKT-
H1ThompsonUS
ii) Referential integrity rule disableH1ThompsonUS
row deletion of a table consisting primary key
matching key values in other table.
BOOK
BOOK
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Book CodeBook_TitlePublisher_CodeTypePriceP01Access 2000 ProcessingM-G1Database76.00P02Teach
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
Yourself Microsoft Access 2000 VisuallyM-G1Database80.00P03Concepts of Database Management SystemP-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database100.00P04Microsoft Access 2000 CompleteT-H1Database59.00P05Database ProcessingT-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
H1Database69.00P06Pengajian MalaysiaF-B1Pengetahuan Am40.00P07Adobe Illustrator 10M-
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
G1Multimedia88.00P08Graphic DesignM-G1Graphic0.00
Table Name : BOOK
Table Name : BOOK
Primary Key : Book_Code
Primary Key : Book_Code
Foreign Key : Publisher_Code
Foreign Key : Publisher_Code
Publisher_Code is a Primary Key for PUBLISHER table, but it is also a Foreign Key for BOOK table. Please
Publisher_Code is a Primary Key for PUBLISHER table, but it is also a Foreign Key for BOOK table. Please
note that Foreign Key value in table BOOK must match the Primary Key value in PUBLISHER table.
note that Foreign Key value in table BOOK must match the Primary Key value in PUBLISHER table.
34
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Definition :
35
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Entity relationship diagram is a diagram that depicts entity relationship model entities, attributes and
relations. It also displays connectivity and cardinality.
A tool used to represent graphically the association between entities in a system. View a system in term
of entity and relationships.
Attribute Attribute
Example :
Example :
Attribute
Composite Attribute
City
ENTITY Postcode
relationshi ENTITY
p
Foreign Key Primary Key
STUDENT M 1 COURSE
Name Registe relationshi
r p
Relationship
Phone_No
Birthdat Course_Name
e
Multivalued Attribute
Attribute Simple Attribute
Derived Age
Attribute
Attribute ENTITY
Relationship between STUDENT and COURSE entity is (M:1).
Relationship between STUDENT and COURSE entity is (M:1).
36
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
IDENTIFY ENTITY
SKETCH ERD
37
ADD ATTRIBUTES
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 1
A company has several departments. Each department has a supervisor and at least one employee.
Employees must be assigned to at least one department. Project will be given to the employee and it will
be done in a group. At least one employee is assigned to one project or more. The important data fields
are the names of the departments, projects, supervisors and employees, as well as the supervisor and
employee number, department code and a unique project number.
Solution :
Step 1 :
Identify entity
. a) Department
b) Supervisor
c) Employee
d) Project
Step 2 :
Identify relationship
a) Each department has one supervisor
38
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 3 :
Sketch ERD
39
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
EMPLOYEE PROJECT
assigned
has
a) Each department has one supervisor
EMPLOYEE PROJECT
assigned
b) Each department has at least one employee. Employees must be assigned to at least one
departments
40
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
1 1
DEPARTMENT has SUPERVISOR
c) Project will be given to the employee and it will be done in a group. At least one employee is
assigned to a project or more.
EMPLOYEE M 1 DEPARTMENT
assigned
Diagram A : Project will be given to the employee and it will be done in a group
Combination of A and B :
41
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
EMPLOYEE M 1 PROJECT
assigned
ERD sketch and cardinality constraint
1 M
EMPLOYEE PROJECT
assigned
EMPLOYEE M N
PROJECT
assigned
Step 5 :
Identify primary key for each entity
Step 6 :
Identify attribute for each entity
1 1
DEPARTMENT has SUPERVISOR
42
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
M
M N
EMPLOYEE assigned PROJECT
Department_No Supervisor_No
Department_Nam
e Supervisor_Name
have
Project_No
Employee_No Project_No
M
1 M EMPLOYEE_PROJECT M 1 PROJECT
EMPLOYEE assigne assigne
d d
Employee_Name Project_Name
43
Employee_No
Department_No
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Or
Project_No
Contoh 2: PROJECT
EMPLOYEE M assigned N
Example 1
Create an ER Diagram for the following requirements with the appropriate attributes for each entity
Employee_No
type and structural constraints for each relationship type.
(a) An INVOICE is written by a SALESREP. Each sales representative can write many
invoices, but each invoice is written by a single sales representative.
(b) The INVOICE is written for a single CUSTOMER. However, each customer can have
many invoices.
(c) An INVOICE can include many details (DETAIL), which describe the products bought by
the customer.
44
(d) The product information is stored in a PRODUCT entity.
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 1 :
Identify entity
a) Invoice
b) Sales Representative
c) Customer
d) Detail
e) Product
Step 2 :
Identify relationship
a) Sales representatives writes Invoice
45
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 3 :
Step 3 :
Sketch ERD
Sketch ERD
SALESREP writes
INVOICE
SALESREP
writes
INVOICE contains
DETAIL
INVOIS / INVOICE
INVOICE written for CUSTOMER
DETAIL
contains references
PRODUCT
DETAIL
references
46
PRODUCT
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 4 :
State cardinality constraint
a) Each sales representative can write many invoices, but each invoice is written by a single sales
representative.
Diagram A
Diagram B
Combination of A and B :
Each Sales representative (SALESREP) writes many INVOICES but each INVOICE is written by a single
SALESREP.
47
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
b) The INVOICE is written for a single CUSTOMER. However, each customer can have many invoices.
Diagram A
Diagram B
Combination of A and B :
An INVOICE is written for a single CUSTOMER, however each CUSTOMER may have many INVOICES.
48
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 4 :
Step 4 :
State cardinality constraint
State cardinality constraint
c) An INVOICE can include many details (DETAIL), which describe the products bought by the
c) An INVOICE can include many details (DETAIL), which describe the products bought by the
customer.
customer.
Diagram A
INVOICE M written for 1 CUSTOMER
Diagram A
Diagram B CUSTOMER
DiagramINVOICE
B M written for 1
Combination of A and B :
Combination of A and B :
An invoice contains many detail lines (DETAIL) for a product. However each DETAIL may exist in one
An invoice contains many detail lines (DETAIL) for a product. However each DETAIL may exist in one
INVOICE only.
INVOICE only.
49
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 4 :
State cardinality constraint
Diagram A
Diagram B
Combination of A and B :
Each DETAIL refers one product. Each PRODUCT may be referred to one or more DETAIL.
50
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
SALESREP
writes
contains
DETAIL
references
1
51
PRODUCT
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 5 :
Identify primary key for each entity
Step 6 :
Identify attribute for each entity
Entity Attribute
52
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
SALESREP SlsRep_Name
1
SlsRep_Tel_No
writes
No_Invoice Cust_No
Inv_Date
M
1
CustTel_No
Cust_No
SlsRep_ID
contains Cust_Name
Cust_Addr
Prod_Code
DETAIL Prod_Qty
M
No_Invoice
Detail_No
references
Prod_Code
Prod_Name
1
53
PRODUCT
Prod_Type
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 3
You have been requested by a travel agency, EXEL Travels, to build a database for storing information
on customers and vacation package that have been booked. Create an ER Diagram based on the
information below:
Each customer has information like Customer Number, Name, Address and Telephone number.
A customer may book more than one holiday package and one holiday package may also be booked
by many customers.
Step 1 :
Identify entity
a) Customer
b) Holiday Package
54
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 2 :
Identify relationship
d) Customer book HOLIDAY PACKAGE.
Step 3 :
Sketch ERD
Step 4 :
State cardinality constraint
Diagram A
A CUSTOMER may book more than one holiday PACKAGE.
Diagram B
One holiday PACKAGE may also be booked by many CUSTOMER
Combination of A and B :
A CUSTOMER may book more than one holiday PACKAGE and one holiday PACKAGE may also be
booked by many CUSTOMERS.
CUSTOMER HOLIDAY PACKAGE
book
55
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 5:
CUSTOMER HOLIDAY PACKAGE
book
Identify primary key for each entity
Step 6 :
Identify attribute for each entity
Entity Attribute
CUSTOMER
CUSTOMER 1 / Cust_No, Cust_Name, Cust_Addr,
M HOLIDAY PACKAGE
Cust_Tel
book
56
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 4
Hospital Jaya is based in Kuala Lumpur. This Hospital has a few wards with several patients. This ward
has a few types, which depends on types of patients.
Patients will be recorded into file that have ID Patient, Patient name, address, phone number, ic number,
categories either VIP or regular patient and a group of blood patient.
Each patient is treated by a doctor at one time but one doctor can treats a number of patients. The
information of doctors recorded are : Doctor ID, name, address, phone number, ic number and
specialization.
Package_Cod
The nurses will be assigned to take care of the patients. Nurses in this hospital are graded
e based on their
Cust_No
Package_Cod
experience, qualification and duration of working in the hospital.
e
Cust_Name Duration
Date
Cust_Tel Cust_No Location
Payment
Cust_Addr
57
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 1 :
Identify entity
a) Ward
b) Patient
c) Doctor
d) Nurse
Step 2 :
Identify relationship
b) Each patient is treated by a doctor at one time but one doctor can be treats a number of
patients.
58
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 3 :
Step 3 :
Sketch ERD
Sketch ERD
assigned treated
by
NURSE assigned PATIENT
NURSE DOCTOR
59
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 4 :
Step 4 :
State cardinality constraint
State cardinality constraint
Diagram A
Diagram A
Diagram B
Diagram B
Combination of A and B :
Combination of A and B :
One ward has many patient while one patient has one ward only
One ward has many patient while one patient has one ward only
60
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
b) Each patient is treated by a doctor at one time but one doctor can treats a number of
b) Each patient is treated by a doctor at one time but one doctor can treats a number of
patient.
patient.
Diagram A
Diagram A
Diagram B
Diagram B
Combination of A and B :
Combination of A and B :
One ward has many patient while one patient has one ward only
One ward has many patient while one patient has one ward only
61
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Diagram A
Diagram B
Combination of A and B :
The nurses will be assigned to ward and one ward has many nurse
62
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 5 :
Identify primary key for each entity
NURSE M
Entity assigned 1
Primary Key WARD
WARD WardID
PATIENT PatientNo
DOCTOR DoctorNo
NURSE NurseNo
Step 6 :
Identify attribute for each entity
63
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
PatientNo
TypeBlood
Type
WardID
PatientIC
WardID
M
1
PatientAdd
Patient
N
PatientTelN
DoctorNo
o
assigned treated
by
NurseNo
DoctorIC
WardID
DoctorNo
NurseN
M 1
NURSE DoctorTelNo
DOCTOR
Experience
NurseAdd Specializatio
DoctorN n
Qualificatio
n
DurationWorking
DoctorAdd
64
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Example 5 :
Beside the above method, ERD can also be creating based on the form or report that will be produce
by the database system that you create.
65
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 1 :
Asset No Type of Start Date End Date Owner No. Owner Owner
rent Name Addres
List down the data (attribute) that can be the primary key s
AS333 Rent 23/7/2003 23/7/2004 PM111 Ahmad Ali Kuala
a) Customer No
Lumpur
b)
AS456 AssetRent
No 1/3/2001 1/3/2002 PM222 Zalia Shah
Ibrahim Alam
c) Owner No
AS278 Lease 20/12/2002 20/12/2003 PM333 Salina Wangsa
Samad Maju
Based on the primary key, we can determine the entity that may be appearing in the ERD.
Step 2 :
Make assumption based on the form.
Assumption:
The form display:
a) Customer make rental
66
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Step 3 :
Sketch ERD
CUSTOMER RENTAL
make
Step 4 :
State cardinality constraint
a) Customer make rental.
Diagram A
ASSET
One customer can make many rental own OWNER
CUSTOMER RENTAL
make
Diagram B
One rental can be make by one customer
have
Combination of A and B :
67
OWNER own ASSET
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Diagram A
One rental may consist of many asset
Diagram B
One asset may have many rental
Combination of A and B :
CUSTOMER 1 M RENTAL
make
CUSTOMER 1 M RENTAL
Diagram B make
One owner may have many asset
Combination of A and B :
68
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
M 1
RENTAL have ASSET
M 1
RENTAL have ASSET
M 1
ASSET own OWNER
69
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
TypesRental
CustomerNo CustomerNo
CustomerAddress AssetNo
CUSTOMER 1 M RENTAL
make
SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY
SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY
RELATIONSHIP M
RELATIONSHIP
StartDate
CustomerName
EndDate
ER Model is the construct and conventions used to create a model of the user data.
ER Model is the construct and conventions used to create a model of the user data.
have
Notation of ER Model :
Notation of ER Model :
OwnerNo
OwnerAddress
1
Entity WNER 1 M ASSET
Entity own
Relationship
Relationship
AssetNo
OwnerName
OwnerNo
Simple Attribute
Simple Attribute
Multivalue Attribute
Multivalue Attribute
Composite Attribute
Composite Attribute
Derived Attribute
Derived Attribute
Entity is a person, place, object, event or concept, which you want to store the information in the
Entity is a person, place, object, event or concept, which you want to store the information in the
database.
database.
70
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Types of attribute :
Types of attribute :
SIMPLE COMPOSITE
SIMPLE COMPOSITE
TYPES OF ATTRIBUTE
MULTIVALUED DERIVED
MULTIVALUED DERIVED
Relational keys are device that relates one entity with another entity in a relationship.
Relational keys are device that relates one entity with another entity in a relationship.
Types of keys :
Types of keys :
Candidate Key
Candidate Key
An attribute or group of attributes that identifies a unique row in a relation. One of the candidate
An attribute or group of attributes that identifies a unique row in a relation. One of the candidate
keys is chosen to be the primary key.
keys is chosen to be the primary key.
Primary key
Primary key
Any of the candidates that is selected to be the key or an attribute that uniquely identifies each row
Any of the candidates that is selected to be the key or an attribute that uniquely identifies each row
in a relation.
in a relation.
Foreign key
Foreign key
An attribute in one table whose values must match the primary key in another table or whose value
An attribute in one table whose values must match the primary key in another table or whose value
must be null.
must be null.
Composite Key 71
Composite Key
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN
Entity Integrity is used to make sure that all data entries are unique and no part of primary key
Entity Integrity is used to make sure that all data entries are unique and no part of primary key
may be null.
may be null.
Referential Integrity is a set of rules that prevents you from changing or deleting a record if
Referential Integrity is a set of rules that prevents you from changing or deleting a record if
matching records exist in a related table.
matching records exist in a related table.
ERD is a diagram that depicts an entity relationship model entities, attributes, and relations. It
ERD is a diagram that depicts an entity relationship model entities, attributes, and relations. It
also displays connectivity and cardinality.
also displays connectivity and cardinality.
IDENTIFY ENTITY
IDENTIFY ENTITY
IDENTIFY RELATIONSHIP
IDENTIFY RELATIONSHIP
SKETCH ERD
SKETCH ERD
ADD ATTRIBUTES
ADD ATTRIBUTES
72