DATABASE
DESIGN
NORSHADILA | MAS AYU | PUZIAHHAIZA
TEKNOLOGI & PERKOMPUTERAN
Copyright ©2021
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted
in any form or by any means, including photocopying, recording, or other electronic or
mechanical methods, without the prior written permission of the publisher, except in the case
of brief quotations embodied in critical reviews and certain other non-commercial uses
permitted by copyright law. For permission requests, write to the publisher, addressed
“Attention: Permission Coordinator,” at the address below.
Politeknik Mersing
Jalan Nitar,
86800 Mersing
Johor Darul Ta’zim
Telephone : 07-7980001
Fax : 07-7980002
Website : http://www.pmj.edu.my
Printed in Malaysia
First Printing, 2021
eISBN : 978-967-2904-15-1
Authors :
Norshadila binti Ahmad Badela, Mas Ayu binti Mohd Ariff, Puziahhaiza binti Pazui
Editorial :
Norshadila binti Ahmad Badela
Graphic Designer :
Mas Ayu binti Mohd Ariff
Page |2
DEDICATIONS
Thanks to ALLAH S.W.T for His mercy and guidance in giving, us full of strength to complete
this e-book.
A lot of thanks to our Head Of Department, Puan Azreen Binti Khamis for all of her support
and guidance in helping us to finish our e-book. Special appreciation also to the PMJ
e-learning team for giving us permission and great cooperations. We also would like to say
thank you to our beloved family for their never-ending support.
Page |3
Page |4
FUNDAMENTAL OF DATABASE SYSTEM
TYPE OF LOGICAL DATA MODEL DATABASE
A collection of information that is PROPERTIES OF DATABASE
organized so that it can be easily :
♪ Accessed Completeness
♪ Managed Integrity
♪ Updated Flexibility
Efficiency
DATABASE MANAGEMENT SYSTEM (DBMS)
DEFINITION
A software that handles the storage, retrieval and updating of data in computer system.
DBMS ARCHITECTURE
CENTRALIZE DISTRIBUTE
Page |5
DATA MODEL
DEFINITION
A logical structure of a database, including the relationships and constraints that
determine how data can be stored and accessed.
TYPE OF LOGICAL DATA THREE-SCHEMA ARCHITECTURE
Model
…END USER
Object Based Logical Model
♪ Entity-Relationship Data Model EXTERNAL EXTERNAL EXTERNAL
LEVEL VIEW VIEW
Record Based Logical Model
♪ Hierarchical Data Model External / CONCEPTUAL SCHEMA
♪ Network Data Model Conceptual
♪ Relational Data Model Mapping
CATEGORIES OF DBMS CONCEPTUAL
LEVEL
Desktop Database
♪ Microsoft-Access Conceptual / INTERNAL SCHEMA
♪ FoxPro Internal
♪ FileMaker Pro Mapping
♪ Paradox
♪ Lotus INTERNAL
LEVEL
STORED DATABASE
Server Database
♪ Oracle
♪ Microsoft SQL Server
♪ IBM
♪ DB2
Page |6
Activity 1A
i. Write the definition of Database.
Answer :
ii. List three (3) importance of databases in everyday life.
a. __________________________________________________________________
b. __________________________________________________________________
c. __________________________________________________________________
iii. Draw the database development process.
Answer :
Page |7
Activity 1B
i. Describe the properties of database.
a. Completeness
___________________________________________________________________
___________________________________________________________________
b. Integrity
___________________________________________________________________
___________________________________________________________________
c. Flexibility
___________________________________________________________________
___________________________________________________________________
d. Efficiency
___________________________________________________________________
___________________________________________________________________
e. Usability
___________________________________________________________________
___________________________________________________________________
ii. DBMS provide several functions in addition to simple file management. List five (5)
functions that DBMS provide.
a. ___________________________________________________________________
b. ___________________________________________________________________
c. ___________________________________________________________________
d. ___________________________________________________________________
e. ___________________________________________________________________
Page |8
iii. Discuss the importance of DBMS.
Answer :
Page |9
Activity 1C
i. List five (5) purposes of database.
Answer :
ii. List three (3) problems using traditional approach and give an example for each
problem.
Answer :
P a g e | 10
iii. Draw and describe two (2) database architecture.
Answer :
P a g e | 11
Activity 1D
i. Describe the following logical Data Model.
a.Object Based Logical Model
Answer :
b. Record Based Logical Model
Answer :
P a g e | 12
ii. Write the correct Data Model for the given explanation.
Each parent can have
many children.
Each child has only one
parent
Tree is defined by path
that traces parent
segments to child
segments, beginning
Rfreopmretsheenltecfot mplex
data relationships more
effectively
Improve database
performance
Impose a database
standard
Performs same basic
functions provided by
hierarchical and
network DBMS
systems.
RDBMS handles all the
complex physical
details.
segments, beginning
from the left
P a g e | 13
Activity 1E
i. Based on the following diagram, fill in the blanks.
ii. List software that use for following categories of DBMS.
a.Desktop Database
Answer :
P a g e | 14
b. Server Database
Answer :
iii. Identify the users of DBMS
Answer :
P a g e | 15
RELATIONAL DATA MODEL
Relational Database Model
A relational database is a type of database that stores and provides access to data points that
are related to one another. A relational database management system (RDBMS) is a database
management system (DBMS) based on the relational model invented by E. F. Codd in year
1970.
Example of RDBMS Packages Objective of Relational Model
IBM My ♥ To allow a high degree of data
DB2 SQL independence
Oracle Microsoft ♥ To provide considerable grounds
SQL Server for dealing with data semantics,
reliability, and redundancy
Dataphor SQLite problems.
♥ To allow the expansion of set-
oriented data manipulation
languages
P a g e | 16
Advantages and Disadvantages of Using Relational Model
Pro Cons
Simplicity: simpler than the Few relational databases have
hierarchical and network model. limits on field lengths which can't
be exceeded.
Easy to use: tables consisting of
rows and columns are quite Relational databases can
natural and simple to understand sometimes become complex as
the amount of data grows, and the
Data independence: The Structure relations between pieces of data
of Relational database can be become more complicated.
changed without having to change
any application. Complex relational database
systems may lead to isolated
Scalable: database should be databases where the information
enlarged to enhance its usability. cannot be shared from one system
to another.
Structural Independence: The
relational database is only
concerned with data and not with
a structure. This can improve the
performance of the model.
Relational Database Structure
Relation Schema
•A relation schema represents the name of table with its
attributes.
Relational •Relation to Tuple
Components (table) •a single row of a table, which contains a single record.
•Tuple (row of Cardinality
record) •Total number of rows present in the Table.
•Cardinality Domain
•A domain is the set of allowable values for one or more
•Attribute attributes.
(Column/
Field) Degree
•The total number of attributes which in the relation is
•Degree called the degree of the relation
(Number of
columns) Attributes
•Each column in a Table which has certain charateristics
•Domain known as attributes.
•Entity
Entity
•Things or object in real world with independent
existence such as person, job,event etc.
P a g e | 17
Types Of Attributes
Simple Attributes Single Valued Attributes
Attribute cannot be further Only have one value for the particular entity
divided such as Age. such as IC number.
Composite Attributes Multivalued Attributes
Comprise of more than one Attributes that can have many values such as
attributes such as address consist student
of postal code and city. can have many certificate like UPSR, PMJ,
SPM ect.
Stored Attributes
Such as date_of_birth
Derived Attributes
Can be computed from other attributes such as Age
Derived from date_of_birth.
Common Relational Model Terms
Table is also called Relation Domains
STUDENT
ID NAME AGE CITY Tuples/Row
21 JB Total of row is
Primary Key 25 KB
20 KL Cardinality
S1 MIMI
S2 TEO
S3 KUMAR
Attributes/Column
Total of column is Degree
P a g e | 18
Relational Scheme
A named of relation defined by a set of attributes and domain name pairs. Its distinct from
all other relation names in relational schema.
The relation schema normally represented as below which Primary Key is underlined.
STUDENT (IDNumber, Name, Gender, PhoneNum, Department, Address)
Relational Keys
Primary Key A candidate key selected to uniquely identify all other attribute
values in any given row. Cannot contain null entries.
Candidate Key A minimal super key. A super key that does not contain a subset of
attributes that is itself a super key
Alternate key An attribute (or combination of attributes) used strictly for data
retrieval purposes.
Foreign key An attribute (or combination of attribute) in one table whose
values must either match the primary key in another table or be
null.
P a g e | 19
Data Integrity
ENTITY INTERGRITY DESCRIPTION
Requirement All primary key are unique, and no part of primary key may
Purpose be null
Guarantees that each will have a unique identity and
REFERENTIAL ensures that foreign key values can properly reference
INTERGRITY primary key values
Requirement
DESCRIPTION
Purpose
A foreign key may have either a null entry – as long as it is
not a part of its table’s primary key – or an entry that
matches the primary key value in a table to which it is
related. (Every non-null foreign key value must reference an
existing primary key value.)
Makes it possible for an attribute NOT to have a
corresponding value, but it will be impossible to have an
invalid entry. The enforcement of the referential integrity
rule makes it impossible to delete a row in one table whose
primary key has mandatory matching foreign key values in
another table.
Integrity Constraints
Entity ● Unique
Integrity ● Primary Key
Domain ♥ Not Null
Integrity ♥ Check
♥ Default
Referential
Integrity Foreign Key
P a g e | 20
Relational Algebra
A procedural query language used to query the database tables to access data in
different ways.
Types of Operators
Select Symbolic
Project notation
Inner Join
Operators Retrieve Outer Join
Information Cross Product
Union
Traditional Intersection
Operator Difference
P a g e | 21
Activity 2A
Explain the following terms briefly.
Tuple
Attribute
Domain
Degree
Cardinality
Relation
P a g e | 22
Activity 2B
Identify attribute, domain, degree, tuple and cardinality for the following tables:
LECTURER
StaffNum ICNum Name Position Department PhoneNum
IT001 781103-03-5333 Abdullah Pensyarah Kejuruteraan 09-8840023
IT002 Perisian 09-8840024
IT003 09-8840025
680923-11-4908 Maimunah Prof Madya Sains
Komputer
801204-06-2323 Kamal Pensyarah Sistem
Maklumat
IT004 600720-06-5380 Jamilah Prof Madya Multimedia 09-8840026
IT005 590101-01-2425 Hakim Professor Kejuruteraan 09-8840027
Perisian
IT006 810303-19-9923 Anis Pensyarah Multimedia 09-8840028
Answer :
Attribute
Domain
Degree
Tuple
Cardinality
P a g e | 23
Activity 2C
Determine the Primary, Candidate, Foreign and Alternate key for the table below.
Branch_info
Branch_Id Branch_Name Branch_Code
1 Computer Science CSE
2 Electronic ECE
3 Mechanical MCE
4 Information Technology ITE
5 Civil CVE
Student_Information
Stu_Id Coll_Id Stu_Name Fath_ Ic_Num Address Branch_Id Session
Name
1 12100 Amir Hadi 1254 Jb 1 2015
1264 Kl 1 2016
2 12101 Haziq Ali 1302 Kluang 3 2015
Kumar 1004 Kb 5 2014
3 12102 Puja 2612 JB 1 2016
Din 1287 KL 2 2015
4 12103 Meera John
Tan
5 12104 Suzie
6 12105 Choo
Answer : -
i. Primary Key
ii. Candidate Key -
iii. Foreign Key -
iv. Alternate Key -
P a g e | 24
Activity 2D
Based on given table, generate the output based on operation below.
a. σ class=’Business’ (Seat)
Answer :
b. πnationality (Booking)
Answer :
P a g e | 25
c. σ nationality = “French” (Booking) X σclass=”Business” (Seat)
Answer :
d. πname (σ class=’Business’(Booking Seat))
Answer :
e. Booking Seat
Answer :
P a g e | 26
Activity 2E
Solve the problem based on tables below:
1. Solve the following relational expressions.
a. PName (RAge>25 (User))
Answer :
P a g e | 27
b. RId>2VAge!=31 (User)
Answer :
c. RUser.OccupationaId=Occupation.OccupationId (User X Occupation)
Answer :
P a g e | 28
d. User Occupation City
Answer :
e. PName,Gender (RCityName = “Boston” (User City))
Answer :
P a g e | 29
ENTITY RELATIONSHIP DIAGRAM (E-R) MODEL &
NORMALIZATION
Normalization
Process of removing redundant data from your tables to improve storage efficiency, data
integrity, and scalability.
Anomalies
• Errors or inconsistencies that may result when a user attempts to update a table that
contains redundant data
• Modification Anomalies
• Changed an incorrect data, sometimes could involve many records having to be
changed, resulted the possibility of some changes being made incorrectly.
• Insert Anomalies
• Impossible process of inserting vital data into the database because other data is
not already there.
• Delete Anomalies
• Unintentionely deleting a data, and the deletion process may result in the
deletion of the only instance of other, required data.
Information Redundancy
• Duplication of data due to the storing of same data multiple times. Redundant
information may waste our storage size.
Functional Dependencies
• Describe relationships between attributes in a relation.
Transitive Dependencies
• A condition in which an attribute is dependent on another attributes that is
not part of the primary key.
P a g e | 30
Steps in Normalization
Remove repeating groups Remove transitive dependencies
UNF 1NF 2NF 3NF
Remove functional dependencies
BOYCE-CODD Normal Form (BCNF)
Boyce Codd normal form (or BCNF or 3.5NF)
BCNF dependencies are like 3NF dependencies but they involve some key
attributes
BCNF often arises when a 1:M relationship is modeled as a M:N
relationship
A relation is in Boyce-Codd Normal Form if and only if every determinant is a
candidate key.
Entity Relationship Diagram
Detailed, logical representation of entities, associations and data elements for an
organization or business.
Must be flexible enough so that it can be used and understood in practically any
environment where information is modelled
Basic Element Of ERD Chen Model P a g e | 31
Types Crow’s Foot Model
Entity
Entity
Attribute LNisatmoef
Attributes
Relationship
Verb phrase
Common Properties for ERD Elements
Element Entity
• Person, place, object, event or concept about which data to be maintained
Element Relationship
• Association between the instances of one or more entity types
Element Attribute
• Named property or characteristic of an entity
weak entity Entity set tha does not have a primary key
Existence of a weak entity set depend on the existence of identifying entity
set
- Must relate to the identifying set via a total, one-to-many relationship set
from the identifying to the weak entity set
- Identifying relationship depicted using a double diamond
Relationships can be classified as either
one-to-one one-to-many many-to-many
P a g e | 32
♪ Chen Model 1 to represent ONE
♪ Crow’s Foot Model M to represent MANY
Exactly ONE ZERO or ONE ONE or MORE
relationship relationship relationship
ZERO or MORE MORE than ONE
relationship relationship
Cardinality & Connectivity
P a g e | 33
Activity 3A
Draw a Chen Model ER diagram for the following:
For each of the following pairs of rules, identify two entity types and one relationship.
State the connectivity and existence of the relationship in each case.
i. A department employs many persons. A person is employed by, at most, one
department.
Answer :
ii. A manager manages, at most, one department. A department is managed by, at
most, one manager.
Answer :
iii. A writer may write many books. A book may be written by many writers.
Answer :
iv. A team consists of many players. A player plays for only one team.
Answer :
v. A flight-leg connects two airports. An airport is used by many flight-legs.
Answer :
P a g e | 34
Activity 3B
You as a database developer has been given a task to develop a simple database of students’
enrolment in Polytechnic Mersing. The following information should be considered:
Lecturer is an entity with the attributes: lecturer name, lecturer ID and lecturer last
name. The lecturer ID attribute is also an identifier.
Class is an entity with the attributes: class ID, class name. The class ID attribute is also
an identifier.
Course is an entity with the attributes: course ID and course name. The course ID
attribute is also an identifier.
Room is an entity with the attribute: room location, room caption and room ID. The
room ID attribute is also an identifier.
And the following about the model's relationships:
a lecturer teaches zero, one or many classes and a class is taught by one lecturer
a course may generate zero, one or many classes and a class comes from one
course
a class is held in one room but a room has many classes
i. Set the attributes of each entity with a correct naming guidelines
Entity Attributes
LECTURER
CLASS
COURSE
ROOM
ii. Draw a Crow’s Model ER diagram for the above requirements :
Answer :
P a g e | 35
Activity 3C
i. Write the business rules that are reflected in ER-diagram below.
Answer :
ii. Write ten cardinalities that are appropriate for this ERD below.
Answer :
P a g e | 36
Activity 3D
Student Student Address Course Name Course Credit Grade Programme Academic
No Name Mersing Code Hours A Advisor
System B Diploma In
2016001 Melissa Analysis And DFC 4 A Digital Hanafi
Abdul 1234 Salim
Malik Design Technology
Human DFP 4
Computer 2345 4
Interaction
DFC
Database 3456
Design
Programming DFC 4 A
Fundamentals 1023 3
3 Diploma In Ahmad
2016115 Arif Danial Ipoh Internet DFC B Information Bukhari
Mohamad Publishing 3123
Technology Hamzah
Multimedia DFM
Technology 4125 A
Multimedia DFM 3 B
Technology 4125 4
Lee Guan 4 A Diploma In Nazlina
Jian Database DFC
2016204 Bertam Design 3456 Computer Muhd
Human DFP
2345 B Science Johari
Computer
Interaction
i. Classify the repeating groups that occur in the above-mentioned table.
Answer :
P a g e | 37
ii. Identify functional dependency of that table and then group it into its entity.
Answer :
iii. Identify transitive dependency of the table and then group it into its entity.
Answer :
P a g e | 38
Activity 3E
Based on the relation PROJECT below, produce the Normalization process from 1NF-3NF.
PROJECT Project_name Staff_no Staff_name Job_classification Charge_hour Hour
DADD
Project_No 00689 Samat Elect Engineer RM 20 20
Progra-mming 00500 Ali Web Developer RM 22 18
1 Multi-media 00444 Azie Web Developer RM 22 15
00123 System Analyst RM 25 30
2 00999 Kamal Technical Support RM 16 56
3 00689 Hazli Elect Engineer RM 20 40
00111 Samat RM 18 35
Anaz Programmer
Answer :
1NF
STAFF
Staff_no Staff_name Job_classification Charge_hour Hour
00689 Samat Elect Engineer RM 20 20
18
00500 Ah Web Developer RM 22 15
30
00444 Azie Web Developer RM 22 56
40
00123 Kamal System Analyst RM 25 35
00999 Hazlim Technical Support RM 16
00689 Samat Elect Engineer RM 20
00111 Anaz Programmer RM 18
STAFF(Project_No, Staff_no, Project_name, Staff_name,
Job_classification, Charge_hour, Hour)
PROJECT Project_name
Project_No DADD
Programming
1 Multimedia
2
3
PROJECT(Project_No, Project_name)
P a g e | 39
Answer :
2NF
P a g e | 40
Answer :
3NF
P a g e | 41
STRUCTURED QUERY LANGUAGE
Structured Query Language is a simple programming language used for accessing and
managing data in relational databases.
Used Of SQL Allow user to create database and relation structure
Perform basic data management tasks, such as the insertion,
modification, and deletion of data from the relations
Parts of •Data Manipulation Language (DML)
SQL •Data Definition Language (DDL)
•Transaction Control Language (TCL)
•Data Control Language (DCL)
• Used to define the database schema. It simply deals with descriptions
DDL of the database schema and is used to create and modify the
structure of database objects in the database.
• Example : CREATE, DROP, ALTER, TURNCATE, COMMENT, RENAME
DML • Deals with the manipulation of data present in the database
• Example : SELECT, INSERT, UPDATE, DELETE
• DCL mainly deals with the rights, permissions and other controls of
DCL the database system.
• Example : GRANT, REVOKE
TCL • TCL commands deals with the transaction within the database.
• Example : COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION
P a g e | 42
SQL CONSTRAINTS
Used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table.
To ensures the accuracy and reliability of the data in the table.
Example : NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK,
DEFAULT, INDEX
SQL DATA TYPES
NUMERIC DATA/TIME CHARACTER/ BINARY
STRING
bit date binary
smallint time char varbinary
decimal datetime varchar varbinary (max)
numeric timestamp
year text image
float varchar (max)
int
SYNTAX SELECT column list
FROM table list
[ WHERE condition list ]
[ GROUP BY column list ]
[ HAVING condition list]
[ ORDER BY column list
[ ASC | DESC ] ];
P a g e | 43
AND,OR,NOT
WHERE < ,<= ,>, >=, <>
CLAUSE
BETWEEN, IS NULL, LIKE, IN
AGGREGATE ARITHMETIC COMPUTATIONS
FUNCTIONS OVER A SET OF ROWS
GROUP BY clause to group HAVING clause used to
the output of aggregate restrict the output of the
functions by one or more
attributes. GROUP BY clause by
selecting only the aggregate
rows that match a given
condition.
P a g e | 44
INNER OUTER
JOIN JOIN
Specify for two or more tables.
If do not specify a join condition, the
DBMS will automatically perform a
Cartesian product of tables which
specify in the FROM clause.
NATURAL
JOIN
P a g e | 45
Activity 4A
1. What is difference between a WHERE clause and a HAVING clause for a SELECT query?
______________________________________________________________________
______________________________________________________________________
2. Explain why it might be appropriate to declare an attribute that contains only digits as
character data type instead of numeric data type.
_______________________________________________________________________
_______________________________________________________________________
3. Explain the difference between an ORDER BY clause and a GROUP BY clause.
________________________________________________________________________
________________________________________________________________________
4. What is the difference between the COUNT aggregate function and the SUM aggregate
function?
________________________________________________________________________
________________________________________________________________________
5. Explain why it would be preferable to use a DATE data type to store data instead of a
character data type.
________________________________________________________________________
________________________________________________________________________
6. What is difference between a DELETE command and a DROP command?
________________________________________________________________________
________________________________________________________________________
7. What is difference between logical operators of AND operator and OR operator?
_______________________________________________________________________
_______________________________________________________________________
P a g e | 46
8. What is function of DISTINCT clause in SQL?
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
9. List the DATE formats which exist in the MySQL.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
10. What is difference between NULL and NOT NULL values?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
P a g e | 47
Activity 4B
i. Write the suitable SQL data type and sample data that created for table structure as
shown below.
DATABASE: CONSULT_COMPANY
JOB
ATTRIBUTE NAME DATA DECLARATION SAMPLE DATA
(FIELD)
JOB_CODE (PK) VARCHAR (10) J10001
(Example)
JOB_DESCRIPTION
JOB_CHARGE_HOUR
JOB_LAST_DATE
EMPLOYEE DATA DECLARATION SAMPLE DATA
ATTRIBUTE NAME
(FIELD) REFER TO THE JOB TABLE
EMP_NO (PK)
EMP_NAME
EMP_HIREDATE
JOB_CODE (FK)
EMP_YEARS
PROJECT DATA DECLARATION SAMPLE DATA
ATTRIBUTE NAME
(FIELD) REFER TO THE EMPLOYEE TABLE
PROJ_NO (PK)
PROJ_NAME
PROJ_VALUE
PROJ_BALANCE
EMP_NO (FK)
P a g e | 48
ASSIGNMENT DATA DECLARATION SAMPLE DATA
ATTRIBUTE NAME
(FIELD) REFER TO THE PROJECT TABLE
REFER TO THE EMPLOYEE TABLE
ASSIGN_NO (PK)
ASSIGN_DATE
PROJ_NO (FK)
EMP_NO (FK)
ASSIGN_CHARGE_HOUR
ii. Create the database and all tables according to the data declaration which consist of
sample data given in Activity 4B (i).
Answer:
P a g e | 49
Activity 4C
i. Underline the SQL statements below using the SweetHome case study which consist of
the following tables.
Guidelines: PRIMARY KEY (_____________) FOREIGN KEY (_ _ _ _ _ _ _ _ _ _ _ _)
a. Branch (branchNo, street, city, postcode);
b. Staff (staffNo, fName, lName, position, gender, DOB, salary, branchNo);
c. PropertyForRent (propertyNo, type, rooms, rent, ownerNo, staffNo, branchNo);
d. Client (clientNo, fName, lName, telNo, prefType, maxRent, email);
e. PrivateOwner (ownerNo, fName, lName, address, telNo, email, password);
f. Viewing (clientNo, propertyNo, viewDate, comments);
ii. Write SQL query for create tables using the suitable data declaration in (i).
Answer: