Database Design
Database Design
DESIGN
NORSHADILA | MAS AYU | PUZIAHHAIZA
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
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
DATABASE
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.
CONCEPTUAL
CONCEPTUAL SCHEMA
LEVEL
CATEGORIES OF DBMS
Conceptual /
Desktop Database Internal
Mapping
♪ Microsoft-Access
♪ FoxPro INTERNAL
INTERNAL SCHEMA
♪ FileMaker Pro LEVEL
♪ Paradox
♪ Lotus
STORED DATABASE
Server Database
♪ Oracle
♪ Microsoft SQL Server
♪ IBM
♪ DB2
Page |6
Activity 1A
Answer :
a. __________________________________________________________________
b. __________________________________________________________________
c. __________________________________________________________________
Answer :
Page |7
Activity 1B
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
Answer :
Page |9
Activity 1C
Answer :
ii. List three (3) problems using traditional approach and give an example for each
problem.
Answer :
P a g e | 10
Answer :
P a g e | 11
Activity 1D
Answer :
Answer :
P a g e | 12
ii. Write the correct Data Model for the given explanation.
Activity 1E
a.Desktop Database
Answer :
P a g e | 14
b. Server Database
Answer :
Answer :
P a g e | 15
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.
Pro Cons
•Relation to Tuple
(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
•Attribute Domain
Relational (Column/ •A domain is the set of allowable values for one or more
Components Field)
attributes.
•Degree
(Number of Degree
columns) •The total number of attributes which in the relation is
called the degree of the relation
•Domain
•Entity Attributes
•Each column in a Table which has certain charateristics
known as attributes.
Entity
•Things or object in real world with independent
existence such as person, job,event etc.
P a g e | 17
Types Of Attributes
Derived Attributes
Can be computed from other attributes such as Age
Derived from date_of_birth.
Domains
STUDENT
Cardinality
S2 TEO 25 KB
S3 KUMAR 20 KL
Attributes/Column
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.
Relational Keys
A minimal super key. A super key that does not contain a subset of
Candidate Key
attributes that is itself a super key
Data Integrity
ENTITY INTERGRITY DESCRIPTION
All primary key are unique, and no part of primary key may
Requirement
be null
Guarantees that each will have a unique identity and
Integrity Constraints
Entity ● Unique
Integrity ● Primary Key
♥ Not Null
Domain ♥ Check
Integrity
♥ 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
notation
Project
Retrieve
Inner Join
Information
Operators
Outer Join
Cross Product
Union
Traditional
Intersection
Operator
Difference
P a g e | 21
Activity 2A
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
Kejuruteraan
IT001 781103-03-5333 Abdullah Pensyarah 09-8840023
Perisian
Sains
IT002 680923-11-4908 Maimunah Prof Madya 09-8840024
Komputer
Sistem
IT003 801204-06-2323 Kamal Pensyarah 09-8840025
Maklumat
Kejuruteraan
IT005 590101-01-2425 Hakim Professor 09-8840027
Perisian
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
Fath_
Stu_Id Coll_Id Stu_Name Ic_Num Address Branch_Id Session
Name
1 12100 Amir Hadi 1254 Jb 1 2015
2 12101 Haziq Ali 1264 Kl 1 2016
3 12102 Puja Kumar 1302 Kluang 3 2015
4 12103 Meera Din 1004 Kb 5 2014
5 12104 Suzie John 2612 JB 1 2016
6 12105 Choo Tan 1287 KL 2 2015
Answer :
i. Primary Key -
Activity 2D
Answer :
b. πnationality (Booking)
Answer :
P a g e | 25
Answer :
Answer :
e. Booking Seat
Answer :
P a g e | 26
Activity 2E
Answer :
P a g e | 27
b. RId>2VAge!=31 (User)
Answer :
Answer :
P a g e | 28
Answer :
Answer :
P a g e | 29
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
Transitive Dependencies
Steps in Normalization
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.
Must be flexible enough so that it can be used and understood in practically any
environment where information is modelled
P a g e | 31
Entity
Entity
Attribute Name
List of
Attributes
Relationship
Verb phrase
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
♪ Chen Model
1 to represent ONE
M to represent MANY
Activity 3A
Answer :
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 :
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.
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
Entity Attributes
LECTURER
CLASS
COURSE
ROOM
Answer :
P a g e | 35
Activity 3C
Answer :
ii. Write ten cardinalities that are appropriate for this ERD below.
Answer :
P a g e | 36
Activity 3D
Database DFC
4 A
Design 3456
Programming DFC
4 A
Fundamentals 1023
Diploma In Ahmad
Arif Danial Internet DFC
2016115 Ipoh 3 B Information Bukhari
Mohamad Publishing 3123
Technology Hamzah
Multimedia DFM
3 A
Technology 4125
Multimedia DFM
3 B
Technology 4125
Database DFC 4 A Diploma In Nazlina
Lee Guan
2016204 Bertam Design 3456 Computer Muhd
Jian
Human DFP 4 B Science Johari
Computer 2345
Interaction
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_No Project_name Staff_no Staff_name Job_classification Charge_hour Hour
00689 Samat Elect Engineer RM 20 20
1 DADD 00500 Ali Web Developer RM 22 18
00444 Azie Web Developer RM 22 15
00123 Kamal System Analyst RM 25 30
2 Progra-mming
00999 Hazli Technical Support RM 16 56
00689 Samat Elect Engineer RM 20 40
3 Multi-media
00111 Anaz Programmer RM 18 35
Answer :
1NF
STAFF
Staff_no Staff_name Job_classification Charge_hour Hour
00689 Samat Elect Engineer RM 20 20
00500 Ah Web Developer RM 22 18
00444 Azie Web Developer RM 22 15
00123 Kamal System Analyst RM 25 30
00999 Hazlim Technical Support RM 16 56
00689 Samat Elect Engineer RM 20 40
00111 Anaz Programmer RM 18 35
STAFF(Project_No, Staff_no, Project_name, Staff_name,
Job_classification, Charge_hour, Hour)
PROJECT
Project_No Project_name
1 DADD
2 Programming
3 Multimedia
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 is a simple programming language used for accessing and
managing data in relational databases.
SQL CONSTRAINTS
Constraints are used to limit the type of data that can go into a table.
CHARACTER/
NUMERIC DATA/TIME BINARY
STRING
AND,OR,NOT
OUTER
JOIN
INNER
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.
_______________________________________________________________________
_______________________________________________________________________
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.
________________________________________________________________________
________________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
P a g e | 46
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
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
ATTRIBUTE NAME
DATA DECLARATION SAMPLE DATA
(FIELD)
EMP_NO (PK)
EMP_NAME
EMP_HIREDATE
EMP_YEARS
PROJECT
ATTRIBUTE NAME
DATA DECLARATION SAMPLE DATA
(FIELD)
PROJ_NO (PK)
PROJ_NAME
PROJ_VALUE
PROJ_BALANCE
ASSIGNMENT
ATTRIBUTE NAME
DATA DECLARATION SAMPLE DATA
(FIELD)
ASSIGN_NO (PK)
ASSIGN_DATE
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.
ii. Write SQL query for create tables using the suitable data declaration in (i).
Answer:
P a g e | 50
Activity 4D
User
Id Name Age Gender OccupationId CityId
1 John 25 Male 1 3
2 Sara 20 Female 3 4
3 Victor 31 Male 2 5
4 Jane 27 Female 1 3
Occupation City
OccupationId OccupationName CityId CityName
1 Software Engineer 1 Halifax
2 Accountant 2 Calgary
3 Pharmacist 3 Boston
4 Library Assistant 4 New York
5 Toronto
Figure 4D
Answer :
P a g e | 51
Answer:
Answer:
iv. Find the user that works as software engineer and age from 25 until 30 only.
Answer:
P a g e | 52
v. Display all the information of user named as Sara and Victor which consist of Name,
Age, Gender, OccupationName and CityName only.
Answer:
P a g e | 53
Activity 4E
Complete the database and answer all the questions below using MySQL.
Database: CAR
CUSTOMER
PHONE_
CUSTID CUSTNAME CAR_NUMBER REGISTER_DATE
NUMBER
C0001 David Teo WUV2318 81691 2014-01-09
C0002 Sulaiman Ali JKL9782 61291 2011-05-07
C0003 Kang Gary MAM123 41972 2010-06-13
C0004 Ji Hyo SAA888 11341 2012-09-26
C0005 Karigalan KUL511 21412 2003-07-18
CAR_COMPONENT
COMPID COMPNAME PRICE
KK001 ISWARA Rear Lamp 100
KK002 WIRA Front Bumper 450
KK003 ISWARA Front Mirror 300
KK004 WAJA Break Lamp 250
KK005 WIRA Front Lamp 600
CLAIM
CLAIMID CLAIM_DATE CUSTID
CL001 2014-04-19 C0005
CL002 2014-01-28 C0001
CL003 2014-02-20 C0003
CL004 2014-09-30 C0002
CL005 2014-12-07 C0004
COMPONENT_CLAIM
CLAIMID COMPID QUANTITY
CL001 KK001 1
CL003 KK003 2
CL002 KK002 1
CL005 KK005 1
CL004 KK004 2
P a g e | 54
Answer:
P a g e | 55
Answer:
P a g e | 56
STEP 3 : Type SQL command to find customer name from CUSTOMER table.
Answer:
P a g e | 57
STEP 4 : Type SQL command to display component ID, component name and price is
between 200 and 400.
Answer:
P a g e | 58
STEP 5 : Open the SQL Editor and type SQL command to display car number begin with J.
Answer:
P a g e | 59
STEP 6 : Open the SQL Editor and type SQL command to display claimID and quantity where
claim number is CL001 and CL004.
Answer:
P a g e | 60
STEP 7 : Open the SQL Editor and type SQL command to find the minimum value for price in
the CAR_COMPONENT table.
Answer:
P a g e | 61
STEP 8 : Open the SQL Editor and type SQL command to find the maximum value for price in
the CAR_COMPONENT table.
Answer:
P a g e | 62
STEP 9 : Open the SQL Editor and type SQL command to find the average value for price in
the CAR_COMPONENT table.
Answer:
P a g e | 63
STEP 10 : Open the SQL Editor and type SQL command to find the sum of price in the
CAR_COMPONENT table.
Answer:
P a g e | 64
STEP 11 : Open the SQL Editor and type SQL command to count the number of customers.
Answer:
P a g e | 65
VALUE OF TPS
• The system must be available during the time period when the users
Continuous are entering transactions.
availability
• A breakdown will disrupt operations or even stop the business.
A C I D
ATOMIC CONSISTENT ISOLATED DURABLE
SYNTAX
START TRANSACTION: begins a new
transaction.
COMMIT: commits the current
transaction, making its changes
permanent.
ROLLBACK: rolls back the current
transaction, canceling its changes.
P a g e | 68
Lost
Update
INTERFERENCE PROBLEM
ARISE FROM
The SIMULTANEOUS ACCESS
Scheduler TO DATABASE
Uncomitted
Dependency
Inconsistent
Retrieval
LOCK
GRANULARITY
CONCURRENCY
TWO-PHASE
CONTROL WITH
DEADLOCKS LOCKING (2PL)
LOCKING
PROTOCOLS
METHODS
LOCKS
P a g e | 69
Two-Phase • The protocol utilizes locks that block other transactions from
Locking accessing the same data during a transaction's life.
(2PL)
protocol • Protocol to prevent lost update problems
RECOVERY TOOLS
Activity 5A
Describe the properties of database transaction according to situation below in Figure 5A.
1. start transaction
2. read (A)
3. A = A–700
4. write (A) Transaction to transfer money from account A to B
5. read(B)
6. B = B+700
7. write(B)
8. commit
Figure 5A
a. Atomicity
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
b. Consistent
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
c. Isolation
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
d. Durability
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
P a g e | 71
Activity 5B
Perform a transaction of a given database in Figure 5B, using SQL statements.
Figure 5B
Many real world scenarios require transaction mostly in banking, finance and trading domain.
Database transaction is implemented in SQL using three keywords START TRANSACTION, COMMIT
and ROLLBACK. Based on the solution of scenario shows in Figure 5B, write the SQL statement to
transfer RM900 from Account _Number 1001 to Account _Number 2002.
Answer:
P a g e | 72
Activity 5C
Table 5C (i)
Figure 5C (i)
Step 4: Type the SQL command to insert all data into STUDENT table
Step 7: Type SQL command with to insert new data into STUDENT table
ICNum: 921120034454
Name: Syed Auris
Email: syris@yahoo.com
P a g e | 74
Step 8: Use select statement again command to display data in STUDENT table. State your
observation.
Step 10: Use select statement again command to display data in STUDENT table. State
your observation.
Figure 5C (ii)
P a g e | 75
Activity 5D
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
P a g e | 76
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
P a g e | 77
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
P a g e | 78
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
P a g e | 79
Activity 5E
Explain the interference problem arise from simultaneous access to database as situated
in figures below.
Figure 5E (i)
Answer:
P a g e | 80
Figure 5E (ii)
Answer:
P a g e | 81
Figure 5E (iii)
Answer :
P a g e | 82
BIBLIOGRAPHY
Coronel, C. & Morris, S. (2018). Database Systems : Design, Implementation & Management
Hogan, R. (2018). A Practical Guide to Database Design. Taylor & Francis. Ltd.
(ISBN 9781138578067)
Watt, A. (2014, October 24). Chapter 11 Functional Dependencies – Database Design – 2nd
functional-dependencies/
Rungta, K. (2021, May 29). Functional Dependency in DBMS: What is, Types and Examples.
Https://Www.Guru99.Com/. https://www.guru99.com/dbms-functional-
dependency.html
http://jhigh.co.uk/Higher/dbases/anomalies.html
https://databasemanagement.fandom.com/wiki/Data_Anomalies
P a g e | 83
ANSWER
Activity 1A Activity 1C
ii.
a. Data Security
Example:
i. The Customer_Transaction file has details about the
total available balance of all customers.
ii. A customer wants information about his/her
account balance.
iii. In a file system it is difficult to give the customer
access to only his/her data in the file.
iii. iv. Thus enforcing security constraints for entire file or
for certain data items are difficult.
v. b. Data Redundancy
Activity 1B Example:
i. At a university, information of a staff might be at all
i. a. Ensures that users can access the data they want. departments.
b. Ensures that data is both consistent (no contradictory ii. It can cause inconsistent data when in update.
data) and correct (no invalid data), and ensures that users 0
c. Data Isolation
trust the database. Example:
c. Ensures that a database can evolve to satisfy changing user i. A teller looking up a balance must be isolated from
requirements. a concurrent transaction involving a withdrawal
from the same account. Only when the withdrawal
d. Ensures that users do not have unduly long response times transaction commits successfully and the teller
when accessing data. looks at the balance again will the new balance be
reported.
e. Ensures that data can be accessed and manipulated in
ways which match user requirements. d. Program/ Data Dependence
Example:
ii.
i. Assume in a banking system there is need to find
out the names of all customers who live within a
Allow Concurrency
particular postal-code area.
Control Security
ii. But there is only a program to generate the list of
Maintain Data Security all customers.
Provide for Backup and Recovery iii. The bank officer has now two choices: either
Control Redundancy obtain the list of all customers and extract the
Allow Data Independence needed information manually or ask a system
Provide Non-Procedural Query Language programmer to write the necessary application
Perform Automatic Query Optimization program.
iv. Both the alternatives are obviously unsatisfactory.
iii.
It helps to make data management more efficient and
effective. e. Concurrent Access Anomalies
A database management system stores, organizes and Example:
manages a large amount of information within a single i. Bank account A containing RM 6000/-. If two
software application. transactions of withdraw funds (RM 500/- and RM
Use of this system increases efficiency of business 1000/- respectively) from account about same
operations and reduces overall costs
P a g e | 84
time, result of the concurrent executions may i. b. Record Based Logical Model are based on application
leave the account in an incorrect state. and user levels of data. They are modelled considering
ii. Program on the behalf of each withdrawal read the logical structure of the objects in the database. This
the old balance, reduce amount and write result data models defines the actual relationship between
back. the data in the entities. There are 3 types of record
iii. If both two programs are concurrent they both based data models defined so far- Hierarchical,
may read the value RM 6000/-.
Network and Relational data models.
Depending on which one writes the value last, the
account may contain either RM 5500/- or RM 5000/-, Advantages :
rather than the correct value of RM 4500/-
It helps to address the issues of flat file data storage.
iii.
In flat files, data will be scattered and there will not
be any proper structuring of the data. This model
Centralize groups the related data into tables and defines the
relationship between the tables, which is not
addressed in flat files.
Activity 1E
Distribute
i.
Number of attributes of a
Degree relation
Number of tuples of relation
Cardinality
Relation used to refer a table c.
in a relational database.
Relation Also be known as
relationship
Activity 2B
d.
Attribute StaffNum, ICNum, Name, Position, Department, PhoneNum
Degree 6
Tuple 6
Cardinality 6
Activity 2C a.
i. Primary Key
Branch_Info table: Branch_Id
Student_Information Table: Coll_Id
Activity 2D
d.
a.
e.
b.
P a g e | 86
ii.
ii.
iii.
iv. Activity 3D
i.
Course Credit
v. Course Name
Code Hours
System Analysis DFC123
4
And Design 4
Activity 3B Human Computer DFP234
4
Interaction 5
i.
DFC345
Entity Attributes Database Design 4
6
LECTURER Lect_ID, Lect_FName, Lect_LName Programming DFC102
CLASS Class_ID, Class_Name, Lect_ID 4
Fundamentals 3
COURSE Course_ID, Course_Name DFC312
ROOM Room_ID, Room_Loc, Room_Cap Internet Publishing 3
3
Multimedia DFM41
3
Technology 25
ii.
Entity Attributes
Student No, Student Name,
Student Address, Programme, Academic
Advisor
Course Code, Course Name, Credit
Course
Hours
ii. Student Student No, Course Code, Grade
Grade
Activity 3C
i. iii.
Entity Attributes
1. A client can own many vehicles. Student Student No, Student
2. Some clients do not own vehicles. Name, Address,
3. A vehicle is owned by one and only one client. Programme
4. A vehicle may generate one or more maintenance Course Course Code, Course
records. Name, Credit Hours
P a g e | 87
PROJECT
HOUR
Project_No Project_name
Staff_no Project_no Hour
1 DADD 00689 1 20
2 Programming 00500 1 18
3 Multimedia 00444 1 15
PROJECT(Project_No, Project_name) 00123 2 30
00999 2 56
00689 3 40
2NF
00111 3 35
STAFF
HOUR(Staff_no, Project_no, Hour)
Charge_
Staff_no Staff_name Job_classification
hour JOB
00689 Samat Elect Engineer RM 20 Job_classification Charge_hour
00500 Ah Web Developer RM 22 Elect Engineer RM 20
00444 Azie Web Developer RM 22 Web Developer RM 22
00123 Kamal System Analyst RM 25 System Analyst RM 25
00999 Hazlim Technical Support RM 16 Technical Support RM 16
00111 Anaz Programmer RM 18 Programmer RM 18
STAFF(Staff_no, Staff_name, Job_classification, Charge_hour) JOB(Job_classification, Charge_hour)
PROJECT
Project_No Project_name
Activity 4A
1 DADD
2 Programming 1. The WHERE clause is used to filter individual
3 Multimedia rows using either a comparison to a literal, or a
PROJECT(Project_No, Project_name) comparison to another column.
The HAVING clause is used to filter groups of rows
HOUR
using an aggregate expression. Often, the same
Staff_no Project_no Hour
aggregate expression is in the SELECT list.
00689 1 20
00500 1 18 You can use WHERE and HAVING in the same SELECT
00444 1 15 statement, if necessary.
00123 2 30 When a SELECT statement is executed, the WHERE
00999 2 56 clause is executed before the GROUP BY clause, if
00689 3 40 one exists. The HAVING clause is executed after the
00111 3 35 GROUP BY clause.
HOUR(Staff_no, Project_No, Hour)
9. The DATE type is used for values with a date part but
no time part. MySQL retrieves and displays DATE
values in 'YYYY-MM-DD' format. The supported range
is '1000-01-01' to '9999-12-31'.
FOREIGN KEY (JOB_CODE) REFERENCES JOB staffNo varchar (10) NOT NULL,
(JOB_CODE)); fName varchar (100),
lName varchar (100),
CREATE TABLE PROJECT ( position varchar (100),
PROJ_NO VARCHAR (10) NOT NULL, gender varchar (10),
EMP_NO VARCHAR (5), DOB date,
salary int,
PROJ_NAME VARCHAR (100),
Foreign Key (branchNo) REFERENCES Branch (branchNo),
PROJ_VALUE INT,
Primary Key (staffNo));
PROJ_BALANCE INT,
PRIMARY KEY (PROJ_NO), Create table Client (
FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE clientNo varchar (10) NOT NULL,
(EMP_NO)); fName varchar (100),
lName varchar (100),
CREATE TABLE ASSIGNMENT ( telNo int,
ASSIGN_NO VARCHAR (8) NOT NULL, prefType varchar (100),
PROJ_NO VARCHAR (10), maxRent int,
EMP_NO VARCHAR (5), email varchar (100),
ASSIGN_DATE DATE, Primary Key (clientNo));
ASSIGN_CHARGE_HOUR INT,
Create table PrivateOwner (
PRIMARY KEY (ASSIGN_NO),
ownerNo varchar (10) NOT NULL,
FOREIGN KEY (PROJ_NO) REFERENCES PROJECT
fName varchar (100),
(PROJ_NO), lName varchar (100),
FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE address varchar (100),
(EMP_NO)); telNo int,
email varchar (100),
INSERT INTO JOB VALUES (‘J10001’,’SENIOR password varchar (100),
EXECUTIVE’, 3,’ 2018-10-07’); Primary Key (ownerNo));
INSERT INTO EMPLOYEE VALUES (‘E1001’,
‘AZKAYRA BINTI EL AZMAN’,’ 2019-02-08,’J1001’, Create table PropertyForRent (
5); propertyNo varchar (10) NOT NULL,
INSERT INTO PROJECT VALUES (‘P10016’, ‘SIME ownerNo varchar (10),
staffNo varchar (10),
DARBY LISTING PROPERTY’, 20000, 25000, ‘E1001’);
branchNo varchar (10),
INSERT INTO ASSIGNMENT VALUES (‘A722912’,
type varchar (50),
‘2019-05-16, ‘P10016’, ‘E1001’, 3); rooms varchar (50),
rent int,
Activity 4C
Foreign Key (ownerNo) REFERENCES PrivateOwner
(ownerNo),
i.
Foreign Key (staffNo) REFERENCES Staff (staffNo),
a. Branch (branchNo, street, city, postcode); Foreign Key (branchNo) REFERENCES Branch (branchNo),
b. Staff (staffNo, fName, lName, position, gender, Primary Key (propertyNo));
DOB, salary, branchNo);
c. PropertyForRent (propertyNo, type, rooms, rent, Create table Viewing (
ownerNo, staffNo, branchNo); clientNo varchar (10),
d. Client (clientNo, fName, lName, telNo, prefType, propertyNo varchar (10),
maxRent, email); viewDate Date,
e. PrivateOwner (ownerNo, fName, lName, address, comments varchar (150),
telNo, email, password); Foreign Key (clientNo) REFERENCES Client (clientNo),
f. Viewing (clientNo, propertyNo, viewDate,
comments); Foreign Key (propertyNo) REFERENCES PropertyForRent
(propertyNo));
ii.
Create table Branch (
branchNo varchar (10) NOT NULL, Activity 4D
street varchar (100),
city varchar (100), i. Create table City (
postcode int, CityId int NOT NULL,
Primary Key (branchNo));
cityName varchar (50),
Primary Key (CityId));
Create table Staff (
P a g e | 90
ii.
INSERT INTO City VALUES (1,'Halifax');
INSERT INTO City VALUES (2,'Calgary');
INSERT INTO City VALUES (3,'Boston');
INSERT INTO City VALUES (4,'New York');
INSERT INTO City VALUES (5,'Toronto');
iii.
SELECT Gender, COUNT (Id)
FROM User
Group by Gender;
STEP 2:
STEP 4 :
STEP 5 :
STEP 6 :
STEP 7 :
STEP 3 :
P a g e | 92
Activity 5C
Step 1:
STEP 9 :
Step 2 :
Step 3 :
STEP 10 :
Step 4 :
Step 5 :
STEP 11 :
Step 6 :
Activity 5A
a. If the transaction fails after step 4 but before step 8,
the updates on A should not be reflected in the Step 7 :
database (rollback).
b. The sum of A and B should not be changed by the
transaction. Step 8 :
c. If another transaction is going to access the partially
updated database between step 4 and 7, it will see an
inconsistent database (with a sum of A and B is less
than it should be).
d. Once the money has been transferred from A to B
(commit), the effect of the transaction must persist.
Activity 5B
start transaction
select balance from Account where
Account_Number='1001';
P a g e | 93
is acquired on a data item to perform a write simultaneously and T1 is rolled back after the T2 has
operation, it is an exclusive lock. Allowing more than already accessed the uncommitted data. Refers to
one transaction to write on the same data item figure above, the original units are 35 then it have
an addition of 100 units. Now, the total units
would lead the database into an inconsistent state.
become 135. For any possibilities, it can occurs an
Read locks are shared because no data value is being error due to any transaction when T1 does not
changed. commit then T2 has read the uncommitted data.
9. Start by pointing out that, although locks prevent Now, T2 has made a new transaction which
serious data inconsistencies, their use may lead to subtracts 30 units from the current value which is
two major problems:1.The transaction schedule 135 units. Suddenly, T1 has rolled back then the
dictated by the locking requirements may not be value now become 35 units back. The correct
execution happens when T1 has rolled back then he
serializable, thus causing data integrity and
or she made a commit, the stored value will hold 35
consistency problems.2.The schedule may create units then subtracts the 30 units, the final result will
deadlocks. Database deadlocks are the equivalent be supposed to 5 units only.
of a traffic gridlock in a big city and are caused by iii. Inconsistent retrievals occur when transaction
two transactions waiting for each other to unlock accesses data before and after another transaction
data. finish working with such data. As shown in Figure 5E
In a real world DBMS, many more transactions can (iii), the original value of a, b and c are 100, 200 and
300. T1 had withdrawn the value of 100 and now the
be executed simultaneously, thereby increasing the
balance become 0. Then, T1 has made an additional
probability of generating deadlocks. Note that of 100 as deposit which the current value is 300 for
deadlocks are possible only if one of the now. At the same time, T2 reads the current value
transactions wants to obtain an exclusive lock on a as 0 after the T1 has made a subtraction. Then, T2
data item; no deadlock condition can exist among reads total of b is still 200 as the original value and
shared locks. not the value of transaction that have been made by
T1. So, it can occurs inconsistent reading of balance
10.
in this account because T1 reads the value of a b and
Log File c are 0, 300 and 300 but then T2 reads another
The file contains information about all changes balance amount as 0, 200 and 500
made to the database. It provides a history of
database changes made by the transactions.
Checkpoint -END-
The checkpoint is the time when all transactions
stop. At this point a checkpoint record is written
to the log and database buffers are written to
disk. Checkpoints are written at periodic
intervals and involve the following operations:
Writing all log records in main memory to
secondary storage
Writing all modified blocks in database
buffers to secondary storage
Writing a checkpoint record to the log file
Activity 5E
AUTHORS
POLITEKNIK MERSING
Jalan Nitar,
86800 Mersing,
Johor
07-7980001 07-7980002
https://pmj.mypolycc.edu.my