IRM 200 - Lecture 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

IRM 200: DATABASE

MANAGEMENT SYSTEMS
Gilbert Mushi
Department of Information and Records Studies
Database Models
There are three common database model
namely;
• Hierarchical
• Network Database and
• Relational
Database Models…
Hierarchical;
• Organizes data in a tree structure
• Typically a one-to-many relationship between
data entities
Network Databases
• Allow both one-to-many and many-to-many
• relationships between data elements
Most databases today are neither hierarchical or
network models
Database Models…
The Relational Database Model (RDBMS)
• Data is organized in tables related by common
fields
• Most widely used database model today
Database Models…
Steps involved in designing RDBMS;
• Identify the purpose of the database
• Determine the tables and fields
• Assign the fields to a table and reorganize as
needed to
• minimize redundancy (normalization – most
databases stop at 3NF)
• Finalize the structure (primary keys, field
properties,
Database Models…
Creating a Relational Database;
– Creating the Tables
• Each table is created using the table structure
developed during the database design process
• In Access, can use Design view or Datasheet
view
Database Models…
Creating a Relational Database;
– Entering and Editing Data
• New data can be added via a form or
Datasheet view (MS Access)
• In either case, the same data is being
manipulated
• Existing data can be migrated to the new
database
Database Models…
Creating a Relational Database;
– Relating Tables
• Once all tables have been created, they can be
related to one another using their primary
keys
Database Models…
Retrieving Information from a Relational Database
– Querying the DB
• A request to see information from a database that
matches specific criteria
• Every DBMS provides tools users can use to query the
• database for information
• Can also write in structured query language (SQL)
• Must be designed to extract information as efficiently
as possible
• Poorly written queries can impact the overall
performance of the system
Database Models…
In maintaining RDBMS table structures can be
modified when needed, such as;
• Adding new indexes to speed up queries
• Deleting obsolete data
• Upgrading database software, installing patches
• Repairing/restoring data that has become corrupt
• Continuing to evaluate and improve security
MS-Access practical
• Develop a simple database which keeps
details of different library materials. The items
details should include item identity, author
name, date of publication, publisher, place of
publication, item type, subject, and item price
Normalization in Database
• Normalization is a process of organizing the
data in database in accordance with a series of
normal forms to avoid data redundancy and
improve data integrity.
• DB should be normalized to avoid three
common anomalies named insertion anomaly,
update anomaly and deletion anomaly
Normalization in Database
• There are four types of normal forms
i) First normal form (1NF)
ii) Second normal form (2NF)
iii) Third normal form (3NF)
iv) Boyce & Codd normal form (BCNF)
1NF
• A relation is in 1NF if it contains an atomic
value.
• An attribute (column) of a table cannot hold
multiple values
Stud_ID Stud_Name Address Stud_mobile
S201 John Mtwara 0713132456
0623153525
S203 Asha Tanga 0784125312
S204 Mrisho Pwani 0753125340
0715735649
1NF…
• The above table is NOT in 1NF rule
A 1NF database should be like this below
Stud_ID Stud_Name Address Stud_mobile
S201 John Mtwara 0713132456
S201 John Mtwara 0623153525
S203 Asha Tanga 0784125312
S204 Mrisho Pwani 0753125340
S204 Mrisho Pwani 0715735649
2NF
• A relation is in second normal form (2NF) if it
is in 1NF and no non-key attribute is partially
dependent on a candidate key
Lecturer_ID Module Lecturer_Age

P101 Appraisal 34

P101 Database 34

P209 Cataloguing 45

P108 Classification 44

P108 Digitization 44
2NF
• The above table is NOT in 2NF rule but the one
below which splits the table into two
Lecturer_Details Lecturer_Module table
Lecturer_ID Lecturer_Age Lecturer_ID Module

P101 Database
P101 34

P101 Appraisal
P209 45
P209 Cataloguing
P108 44
P108 Classification
3NF
• A relation is in third normal form (3NF) if it is
in 2NF and no non-key attribute is transitively
dependent on a candidate key
Cust_ID Cust_Na Cust_Addr Cust_Region Cust_Distr Cust_Stree
me ess ict t
123 Ally Box 3000 Morogoro Ifakara Mbuyuni

124 Magawa Box 259 Dodoma Kondoa Mtakuja

125 Zainabu Box 997 Kilimanjaro Moshi TPC

126 Kwayu Box 456 Kigoma Uvinza Machako


3NF…
• The above table is not in 3NF rule
• Cust_Region, Cust_District & Cust_Street
dependent on Cust_Address. And, Cust_Address
is dependent on Cust_id that makes non-prime
attributes (Cust_Region, Cust_District &
Cust_Street) transitively dependent on super key
(Cust_id). This violates the rule of 3NF
• To comply with 3NF rule, the table must broke in
two to remove transitive dependency
3NF…
Customer_Table Customer_Address
Cust_ID Cust_Nam Cust_Addres Cust_Ad Cust_Regio Cust_Addres Cust_Street
e s dress n s

123 Ally Box 3000 Box Morogo Ifakara Mbuyuni


3000 ro
124 Magawa Box 259 Box Dodoma Kondoa Mtakuja
259
125 Zainabu Box 997 Box Kilimanj Moshi TPC
997 aro
126 Kwayu Box 456 Box Kigoma Uvinza Machako
456
Boyce-Codd normal form (BCNF)
• It is an advance version of 3NF that’s why it is
also referred as 3.5NF.
• BCNF is stricter than 3NF. A table complies
with BCNF if it is in 3NF and for
every functional dependency should be the
super key of the table.
• Look an example below
BCNF…
Student enrollment table with stud_id, module
and lecturer
Stud_ID Module Lecturer
B002 Database Dr. Bruno

B002 Networking Mr. Mashaka

B013 Database Mr. Raymond

B018 Marketing Dr. Adrian

B010 Database Dr. Bruno


BCNF…
In the table above;
• One student can enroll multiple module i.e B002
• For each subject, lecturer is assigned to the stdnt
• Multiple lecturers can teach one module
Stud_ID and Module together form a primary key
Note that one lecturer teaches only one module, but
one module may have two different lecturers.
Hence, there is a dependency between module and
lecturer here, where module depends on the
lecturer name.
BCNF…
• The table is 3NF but it is NOT Boyce-Codd normal
form
Because:
• Stud_ID and Module form primary key with
module column been a prime attribute
• But there is one more dependency, lecturer and
module
• While module is a prime attribute, lecturer is
a non-prime attribute, which is not allowed by
BCNF
BCNF…
• To make this relation(table) satisfy BCNF, we will
decompose this table into two tables, student table
and lecturer table.
Student table Lecturer table
Stud_ID Lecturer_ID Lecturer_ID Lecturer_Name Module
B002 1001 1001 Dr. Bruno Database
1002 Mr. Raymond Database
B002 1004

B018 1003 1003 Dr. Adrian Marketing


1004 Mr. Mashaka Networki
B013 1002
ng
Normalization and design
Normalization is related to DB design;
• A database should normally be in 3NF at least
• If your design leads to a non-3NF DB, then you
might want to revise it
When you find you have a non-3NF DB;
• Identify the Functional Dependencies that are
causing a problem
• Think if they will lead to any insert, update, or
delete anomalies
• Try to remove them

You might also like