E R Diagram

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 72

CHAPTER 2

FUNDAMENTAL OF ENTITY
RELATIONSHIP (ER)
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Objective

At the end of this chapter, students should be able to :

 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 Entity Relationship (ER) Model

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.

A Car Purchasing Model

Relationship

FACTORY CAR CUSTOMER

Entity

2
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Explanation for diagram :

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.

Example 1: ER Model of Book Information System

PUBLISHER BOOK AUTHOR

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

PUBLISHER 1 publish M BOOK

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

PUBLISHER 1 publish M BOOK


G
M

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

Example 2: ER Model of Borrowing Book Process


Example 2: ER Model of Borrowing Book Process

Step 2 :
Step 2 :
STUDENTBook_No BOOK AUTHOR
Book_No Author_ID
Book_Title

BOOK M written N AUTHOR


by
borrows borrows written by
ISDN
Book_Price Author_Name
Author_ID
The picture above shows a student borrowing a book. The book was written by an author.
The picture above shows a student borrowing a book. The book was written by an author.

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_I Student_ID Book_No


Book_Title
D
Complete ERD Book_Price
Complete ERD

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

Note: Book number is set by the Author_ID

librarian
N
5 AUTHOR
Author_Name
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Example 3: ER Model of Employee and Project Storing Information Process

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

DEPARTMENT EMPLOYEE PROJECT


Step 2 :

have handle

Complete ERD
DeptNo EmployeeNo
DeptNo

DEPARTMENT 1 have M EMPLOYEE

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

DEPARTMENT 1 have M EMPLOYEE

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

 There are 3 elements of ER Model:


- Entities
- Attributes
- Relationship

Explanation for elements of E-R :

Element Symbol Definition

Entity A person, place, object, event


or concept, which you want to
store information in database.

A property or characteristic of
Attribute
an entity or relationship type.

Interaction of 2 entities
represented by a verb.

Relationship

2.1.3 Notation of ER Model

9
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Entity

Relationship

Simple Attribute

Multivalue Attribute

Composite Attribute

Derived Attribute

2.1 Entities And Attributes

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:

PERSON Example: Student, Employee


PLACE Example: Country, Branch
OBJECT Example: Product, Building
EVENT Example: Student Registration, Payment
CONCEPT Example: Course, Order

 What is Entity Type?


- Entity type is a collection of entities, which share the same characteristic.

 What is Entity Instances


Example of Entity
- Entity Type and
instances Entity
are data forInstances
entity type.

Entity Type :- BOOK

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

Two entity instances for BOOK :

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).

2.2.2 Atribut / Attribute


Type
Book_Cod
Price
e
 Attribute is a character of an entity or object.

 Attribute has a name and a data type. BOOK

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

12 Publisher_Name and City.


Attributes for the PUBLISHER are Publisher_Code,
Attributes for the PUBLISHER are Publisher_Code, Publisher_Name and City.
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Author_No

AUTHOR

Author_Name

Attributes for the entity AUTHOR are Author_No and Author_Name.


Attributes for the entity AUTHOR are Author_No and Author_Name.
2.2.3 Types of Attributes

SIMPLE COMPOSITE
SIMPLE COMPOSITE

TYPES OF ATTRIBUTE

13

MULTIVALUED DERIVED
MULTIVALUED DERIVED
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Types of Attributes Definition Example

An attribute that holds a single


SIMPLE value.
Name
Example: The majority of
people have only one name.

An attribute that have more


than one value.
MULTIVALUED Example: A staff may have 2 Phone_num
tel_no, which are home tel_no
and mobile tel_no (hand phone).

2.2.3 Types of Attributes ( Continue)

Types of Attributes Definition Example


State
Pos Code

Town
14

Address
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

An attribute that can be broken


COMPOSITE down into component parts.

Example: An address
comprises of city, postcode and
state.

An attribute where the values


DERIVED can be calculated from related Date_of_birth
attribute.

Example: Age can be known


from Date_of_Birth. Age

2.3 Relationship And Cardinality Constraint

15
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Azhar ( Grandfather) Zainab ( Grandmother)

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

 Definition: Relationships is an association between entities, which is defined by a diamond


shaped symbol in an E-R diagram.

2.3.2 Cardinality Constraint

 Definition: The number of entity type, which is involved in a relationship.


 Types of cardinality constraints

a) One to One Relationship (1:1)


Definition: Maximum one X for each Y and 1 Y for each X.

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.

b) One to Many (1:M)


Definition: Maximum one X for each Y and possibly many Y’s for each X.

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.

2.3.2 Cardinality Constraint (Continue)

c) Many to One (M:1)

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

(d) Many to Many (M:N)


Definition: Possibly many X’s ISDN
for each Y and many Y’s for each X.

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

(i) A book may have many authors.

Authtor_ID
Author_ID
Author_ID
ISDNISDN

MM N 1
BOOK written by AUTHOR
BOOK authoring AUTHOR

(ii) An author may write more than one book.


ISDN

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

2.3.3 Examples of Relationship

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

DEPARTMENT 1 have M EMPLOYEE

Name
Dept_Name Address

One DEPARTMENT have many EMPLOYEES.

Diagram B :
EmployeeNo
DeptN DeptNo
o

1 have 1
EMPLOYEE DEPARTMENT

Name
Combination of Diagram A & B:
Address Dept_Name

One EMPLOYEE work at one DEPARTMENT.

DeptNo EmployeeNo
DeptNo

One to Many Relationship (1:M) – One


1 DEPARTMENT have many EMPLOYEES while one
DEPARTMENT have M EMPLOYEE
EMPLOYEE can be in one DEPARTMENT only.

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:

One PROJECT is handled by many EMPLOYEE.


Diagram A :

EmployeeNo
Combination of Diagram A & B:ProjectN ProjectN
DeptNo
o o

1 1
EMPLOYEE PROJECT
handle
by
Name
Deadlin
Address e

One EMPLOYEE handles one PROJECT.

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

One PUBLISHER publish many BOOKS

Diagram B :

One BOOK is published by one PUBLISHER only.

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

PUBLISHER 1 publish 1 BOOK


Combination of Diagram A & B:

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

PUBLISHER 1 publish M BOOK

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 :

One LECTURER may teach more than one SUBJECT.

Diagram B

SUBJECT is taught by more than one LECTURER.

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.

STUDENT register COURSE. Subject_Cod


Lecturer_ID Subject_Cod e
e
Diagram A :
M 1
LECTURER teach SUBJECT

A new STUDENT registers a COURSE. Subject_Cod


Lecturer_I Subject_Cod Lecturer_I e
D e D
Diagram B : M N
LECTURER teach SUBJECT

A COURSE is registered by many STUDENTS.

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

Student_ID Course_Cod Course_Cod


e e

M 1
STUDENT register COURSE

Course_Name

Combination of Diagram A & B:

Student_ID Course_Cod Course_Cod


e e

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

2.4 Relational Key And Integrity Constraint

Relational Key Definition


- A key consists of one or more attributes that can identify a row.

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.

Why we need Relational Key?


- Relational key enable us to link the tables together in a database for easier data access
storage.

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.

* One table can have more than 1 candidate key *


* One table can have more than 1 candidate key *

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

PUBLISHER 1 publish M BOOK

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

PUBLISHER 1 publish M BOOK

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

BOOK M written by N AUTHOR

Title Publisher_Cod
e Author_Name
Book_Code

Book_Code

Author_No
Author_No
Price Type

BOOK 1 M BOOK_AUTHOR M 1 AUTHOR

Title Publisher_Cod
e Author_Name
Book_Code

Composite Entity (Conceptual Entity)


Composite Entity (Conceptual Entity)
31
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

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

2.4.2 Integrity Constraints / Integrity Rules

 2 types of integrity constraint are Entity Integrity and Referential Integrity.

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

2.4 Entity Relationship Diagram (ERD)

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

Primary Key Address


Course_Code
Course_Code
Student_ID
Attribute

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).

 Attribute for STUDENT :


 Attribute for STUDENT :
- Student_ID (Primary key)
- Student_ID (Primary key)
- Name (Simple attribute)
- Name (Simple attribute)
- Address (Composite attribute)
- Address (Composite attribute)
- Phone_No (Multivalued attribute)
- Phone_No (Multivalued attribute)
- Age (Derived attribute)
- Age (Derived attribute)
- Course_Code (Foreign attribute)
- Course_Code (Foreign attribute)

 Attribute for COURSE :


 Attribute for COURSE :
- Course_Code ( Primary key)
- Course_Code ( Primary key)
- Course_Name (Simple attribute)
- Course_Name (Simple attribute)

36
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

IDENTIFY ENTITY

ENTITI / IDENTIFY RELATIONSHIP

SKETCH ERD

STATE CARDINALITY CONSTRAINTS

2.6 Steps to Develop ER Diagram

SPECIFY PRIMARY KEYS

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

b) Each department has at least one employee

How to Draw ER Diagram

38
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

c) Employees must be assigned to at least one departments.

d) Project will be given to the employee

Step 3 :
Sketch ERD

DEPARTMENT has SUPERVISOR

DEPARTMENT has EMPLOYEE

EMPLOYEE has DEPARTMENT

39
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

EMPLOYEE PROJECT
assigned

DEPARTMENT has SUPERVISOR


Step 4 :
State cardinality constraint

Based on the problem above, cardinality constraint are :

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

Diagram A : Each department has at least one employee

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

Diagram B : At least one employee is assigned to a project or more

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

Entiti / Entity Kunci Primer / Primary Key


DEPARTMENT Department_No
EMPLOYEE Employee_No
SUPERVISOR Supervisor_No
PROJECT Project_No

Step 6 :
Identify attribute for each entity

Entiti / Entity Atribut / Attribute


DEPARTMENT Department_Name
EMPLOYEE Employee_Name
SUPERVISOR Supervisor_Name
PROJECT Project_Name

1 1
DEPARTMENT has SUPERVISOR

42
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

has New entity will be transform because of M:N relationship

Complete ERD diagram

M
M N
EMPLOYEE assigned PROJECT

Department_No Supervisor_No

DEPARTMENT 1 has 1 SUPERVISOR

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

b) Invoice written for Customer

c) Invoice contains Detail

(d) Detail references Product

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

INVOICE written for


CUSTOMER

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

Each Sales representative (SALESREP) writes many INVOICES.

Diagram B

Each invoice is written by a single sales representative.

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

SALESREP 1 writes M INVOICE


Step 4 :
State cardinality constraint

b) The INVOICE is written for a single CUSTOMER. However, each customer can have many invoices.

Diagram A

The INVOICE is written for a single CUSTOMER.


SALESREP 1 writes 1 INVOICE

Diagram B

Each CUSTOMER may have many INVOICES.

SALESREP 1 writes M INVOICE

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

INVOICE 1 written for 1 CUSTOMER

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

An invoice contains many detail lines (DETAIL).


An invoice contains many detail lines (DETAIL).

INVOICE 1 contains M DETAIL

Diagram B CUSTOMER
DiagramINVOICE
B M written for 1

Each DETAIL may exist in an INVOICE.


Each DETAIL may exist in an INVOICE.

INVOICE 1 contains 1 DETAIL

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.

INVOICE 1 contains M DETAIL

49
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Step 4 :
State cardinality constraint

d) The product information (DETAIL) is stored in a PRODUCT entity.

Diagram A

Each DETAIL refers to one product.

Diagram B

Each PRODUCT may be referred to one or more DETAIL

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

DETAIL 1 references 1 PRODUCT


ERD sketch and cardinality constraint
ERD sketch and cardinality constraint

SALESREP

DETAIL M references 1 PRODUCT

writes

INVOICE M written for 1 CUSTOMER

DETAIL 1 M references 1 PRODUCT

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

Entity Primary Key


INVOICE Inv_No
SALESREP SlsRep_ID
CUSTOMER Cust_No
DETAIL Detail_No
PRODUCT Product_Code

Step 6 :
Identify attribute for each entity

Entity Attribute

INVOICE Inv_No, Inv_date

SALESREP SlsRep_ID, SlsRep_Name, SlsRep_Tel_No

CUSTOMER Cust_No, Cust_Name, Cust_Addr, Cust_Tel_No

DETAIL Detail_No, Prod_Qty

PRODUCT Prod_ Code, Product_Name, Prod_Type

52
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Complete ERD Diagram


Complete ERD Diagram
/ SlsRep_ID

SALESREP SlsRep_Name

1
SlsRep_Tel_No

writes

No_Invoice Cust_No

Inv_Date
M

INVOICE M written for 1 CUSTOMER

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.

 Customers may have many addresses and telephone numbers.

 A customer may book more than one holiday package and one holiday package may also be booked
by many customers.

 Examples of payments according to booked holiday package :

Package A : New Zealand (3 days) - RM 3500

Package B : New Zealand (7 days) - RM 5000

Package C : New Zealand (10 days) - RM5990

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

a) Customer book HOLIDAY PACKAGE.

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

Entity Primary Key


CUSTOMER Cust_No
HOLIDAY PACKAGE Package_Code

Step 6 :
Identify attribute for each entity

Entity Attribute

CUSTOMER
CUSTOMER 1 / Cust_No, Cust_Name, Cust_Addr,
M HOLIDAY PACKAGE
Cust_Tel
book

HOLIDAY PACKAGE Package_Code, Location, Duration, Payment

Complete ERD Diagram


CUSTOMER M 1 HOLIDAY PACKAGE
book

CUSTOMER M N HOLIDAY PACKAGE


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

CUSTOMER M N HOLIDAY PACKAGE


book

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

a) This Hospital has a few wards with several patients.

b) Each patient is treated by a doctor at one time but one doctor can be treats a number of
patients.

c) The nurses will be assigned to take care of the patients.

58
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Step 3 :
Step 3 :
Sketch ERD
Sketch ERD

WARD has PATIENT

PATIENT treated DOCTOR


by

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

a) This Hospital has a few wards with several patients.


a) This Hospital has a few wards with several patients.

Diagram A
Diagram A

One ward has many patient


One ward has many patient

WARD 1 has M PATIENT

Diagram B
Diagram B

One patient has one ward only


One patient has one ward only

WARD 1 has 1 PATIENT

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

WARD 1 has M PATIENT

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

One patient is treated by one doctor


One patient is treated by one doctor

PATIENT 1 treated 1 DOCTOR


by

Diagram B
Diagram B

One doctor can treats many patient.


One doctor can treats many patient.

PATIENT M treated 1 DOCTOR


by

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

PATIENT M treated 1 DOCTOR


by

61
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

c) The nurses will be assigned to ward to take care of the patients.

Diagram A

The nurses will be assigned to ward

Diagram B

One ward has many nurse.

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

NURSE 1 assigned 1 WARD

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

NURSEEntity M assigned Attribute


1 WARD

WARD Type , WardID

PATIENT PatientNo, PatientN, PatientAdd, PatientIC, PatientTelNo,


Category, TypeBlood

DOCTOR DoctorNo, DoctorN, DoctorAdd, DoctorTelNo, DoctorIC,


Specialization

NURSE NurseNo, NurseN, NurseAdd, Experience, Qualification,


DurationWorking

63
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Complete ERD diagram


Complete ERD diagram
Category

PatientNo
TypeBlood
Type
WardID
PatientIC
WardID

WARD has M PATIENT

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 :

Based on the form below, draw a complete ERD diagram.

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

Customer No : PN123 Customer Name : Azizah Ahmad

Address : 45-6-8, Menara Anggerik, 51000 Kuala Lumpur

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.

The possible entities are: CUSTOMER, ASSET, OWNER

Step 2 :
Make assumption based on the form.

Assumption:
The form display:
a) Customer make rental

b) Rental based on asset

c) Asset is own by owner

66
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

Step 3 :
Sketch ERD

CUSTOMER RENTAL
make

RENTAL have ASSET

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

b) Rental based on asset

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

c) Asset is own by owner


1 1
CUSTOMER RENTAL
Diagram A make
One asset is own by one owner

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

RENTAL 1 have 1 ASSET

M 1
RENTAL have ASSET

Complete ERD diagram

M 1
RENTAL have ASSET

ASSET 1 own 1 OWNER

ASSET M own 1 OWNER

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.

Attribute is a character of an entity or object.


Attribute is a character of an entity or object.

70
CHAPTER 2: FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
IDB2024: DATA ANALYSIS & DATABASE DESIGN

SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY


SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY
RELATIONSHIP
RELATIONSHIP

Types of attribute :
Types of attribute :
SIMPLE COMPOSITE
SIMPLE COMPOSITE

TYPES OF ATTRIBUTE

MULTIVALUED DERIVED
MULTIVALUED DERIVED

Relationship is an association between entities; which is defined by a diamond shaped in an ER


Relationship is an association between entities; which is defined by a diamond shaped in an ER
Diagram.
Diagram.

Cardinality constraint is the number of entity type, which is involved in a relationship.


Cardinality constraint is the number of entity type, which is involved in a relationship.

There are 3 types of cardinality constraint, 1:1, 1:M, M:N.


There are 3 types of cardinality constraint, 1:1, 1:M, M:N.

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

SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY


SUMMARY FOR CHAPTER 2 : FUNDAMENTAL OF ENTITY
RELATIONSHIP
RELATIONSHIP

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.

Steps to draw an ERD :


Steps to draw an ERD :

IDENTIFY ENTITY
IDENTIFY ENTITY

IDENTIFY RELATIONSHIP
IDENTIFY RELATIONSHIP

SKETCH ERD
SKETCH ERD

STATE CARDINALITY CONSTRAINTS


STATE CARDINALITY CONSTRAINTS

SPECIFY PRIMARY KEYS


SPECIFY PRIMARY KEYS

ADD ATTRIBUTES
ADD ATTRIBUTES
72

You might also like