Ss3 Data Processing 1st Term Final Handout
Ss3 Data Processing 1st Term Final Handout
1
NORMALIZATION
THEORY
• At the end of this lesson, students should be able to
i) Define normalization;
ii) State the goals of Normalization;
iii) Mention the three anomalies in databases.
2
NORMALIZATION
• What is Normalization?
• Normalization is the process of efficiently organizing data in a database.
T2
• Objectives:
i) Define normalization;
i) Define normalization;
i) Define normalization;
8
DELETE ANOMALY
i) Define normalization;
9
• Delete anomaly. All information about Dr. Giddens is lost if
he temporarily ceases to be assigned to any course.
• Objectives:
i) Define normalization;
• Objectives:
i) Define normalization;
12
ACTIVITY…. 2 MINUTES.
1. What do you call the process of reducing undesirable
properties in a database?
2. Storing the same data in more than one table is technically
termed data ___________
3. A situation where modifying the value of a field leads to
database inconsistency is termed _________
4. A situation when it is impossible to add certain types of
data to the database is termed ____ anomaly
5. If the removal of data leads to unintended loss of
additional data, then we have ________ anomaly
13
SEE THIRD TERM Q BANK
The database design prevents some data from being stored due
to
A) Deletion anomalies
B) Insertion anomalies
C) Update anomalies
D) Selection anomalies
14
NORMAL FORMS
15
NORMAL FORMS
• Normal Form (NF) is a set of rules or guidelines used to
structure and organize the data within database tables to
minimize data redundancy, improve data integrity, and reduce
database anomalies.
The normal forms are:
1NF - First Normal Form
2NF - Second Normal Form
3NF - Third Normal Form
BCNF - Boyce-Codd Normal Form i) Define normal forms;
5NF - Fifth Normal Form ii) Enumerate examples
of normal forms
iii) Decompose tables to
at least the 1NF.
FIRST NORMAL FORM (1NF)
1. Every field in 1NF must be atomic, that is, indivisible. In other words, there must be no “multi-valued”
field
T1
SOLUTION
I Name Age Interests
i) Define normal forms; d
In
table T4, Price depends on item but not 22
on colour.
THE TABLES IN
2NF
T5
T6
Item Colour
T-shirt Red Item Price Tax
T-shirt Blue T-shirt 12.00 0.60
Polo Red Polo 12.00 0.60
Polo Yellow Sweat 25.00 1.25
shirt
Sweatshirt Blue
Sweatshirt black
23
3NF
• The table must FIRT be in 2NF
• No non-key field depends upon another. All non-
key fields must depend ONLY on the primary key.
• Table T6 below is not in 3NF…. Why?
T5 T6
Item Price Tax
Item Colour
T-shirt 12:00 0.60
T-shirt Red
T-shirt Blue Polo 12:00 0.60
Polo Red Sweatshirt 25:00 1.25
Polo Yellow i) Define normal forms;
Sweatshirt Blue
ii) Enumerate examples
Sweatshirt black
of normal forms
iii) Decompose tables to
at least the 1NF.
TABLES IN 3NF
T5
2NF
1. Must be in 1NF
2. No partial dependencies on a composite key
i) Define normal forms;
3NF ii) Enumerate examples
1. Must be in 2NF of normal forms
27
2. No dependencies on non-key attributes iii) Decompose tables to
at least the 1NF.
EXTRA WORK
Solution
Dept Knowledge First name Last
i) Define normal forms;
name
iOS Java Thomas Mueller ii) Enumerate examples
iOS C++ Thomas Mueller of normal forms
iOS PHP Ursula Meier iii) Decompose tables to
iOS Java Ursula Meier at least the 1NF.
Android C++ Igor Mueller 29
31
CLASS WORK
1. With the aid of a table vividly explain composite
key?
2. Normalise the table below to 1NF and 2NF.
Item Colour Price Tax
32
SOLUTION
36
SOLUTION
Answers
1. Foreign key
2. Composite key
3. Candidate key
4. Account number
37
PROGRAMMING TIPS
38
Q) THE PROCESS OF EFFICIENTLY
ORGANIZING DATA IN A
DATABASE IS…
Normalization
Redundancy
Rationalization
39
DATABASE INDEXES
• At the end of this lesson students should be able to
i) Describe database index;
ii) State the advantages of database index;
iii) Enumerate and explain the various types of indexes;
iv) Create database index using MS Access.
40
DATABASE
INDEXES
See the index at the end of a
book.
Why would you use a book
index?
Why do you need Database
indexes.
Indexes make it faster to
find specific records in a
database.
41
DATABASE INDEXING
What is DATABASE INDEX? i) Describe database index;
ii) State the advantages of
• A database index is a list of keys (or
database index;
keywords), each of which identifies a
iii) Enumerate and explain the
unique record. various types of indexes;
• Index File: an index file is a table with two iv) Create database index
columns: one stores a sorted list of the using MS Access.
values in the field being indexed and the
second stores pointers that give the location
of each record in the table.
• That is, an index is a file which consists of
records (called index entries) of the form…
42
search key value pointer to block in data file
CLASS ACTIVITY
43
INDEX FILE
44
TYPES OF INDEX
1. Primary Index: Primary index is defined on an ordered
data file. The data file is ordered on a key field. The key
field is generally the primary key of the relation. E.g.
Employee ID or RegNo as in the table below.
45
2. Secondary (Non-clustering) index : An index that is defined on
a non-ordering field of the data file.
46
ASSIGNMENT
47
CREATING A SINGLE-FIELD
INDEX IN MS ACCESS
• In the Navigation Pane, right-click the name of the table that
you want to create the index in, and then click Design View on
the shortcut menu.
• Click the Field Name for the field that you want to index.
• Under Field Properties, click the General tab.
• In the Indexed property, click Yes (Duplicates OK) if you want
to allow duplicates, or Yes (No Duplicates) to create a unique
index.
• To save your changes, click Save
48
MS ACCESS PRACTICAL
49
BASIC SQL
50
WHAT IS SQL
• SQL stands for Structured Query Language.
• It is the standard scripting language for manipulating
databases and their objects.
• Created by Donald D. Chamberlin and Raymond F. Boyce in the
1970s.
51
WHAT CAN YOU DO WITH SQL?
52
CREATE TABLES
• Using SQL
Open Access
Create a database
Name it Your name-Current date
i) Describe SQL;
4. Click on SQL
ii) State the uses of SQL in databases;
NB: You need to refresh the table using the F5 function key to
see the values you inserted OR Close the table and reopen
it.
60
SQL PROJECT. FOLLOW THE INSTRUCTION
CAREFULLY.
1) Create a database using your Surname & First name as the database name.
2) Create the table below (Customer) using SQL. Save the SQL as Qtable.
3) Insert the values in the given table into your table using SQL. Save this SQL as QInsertData. Note: You must
change the customer’s names to any names of your choice.
4) Using SQL, extract all the CustomerName, Phone and State. Save this SQL as QExtractData.
62
PRACTICAL TEST
• Next slide
63
WRITE THE SQL CODE TO
CREATE THE TABLE BELOW
Use the following info for
each data: PhoneList
ID
ID (INT and primary key) Surname
Surname (VarChar)
First_Name (VarChar) First_Name
Phone (Text) Phone
State (Text)
State
• Save the database as your name and date.
• Insert the records below into the table created using sql
code:
• 1, Goodluck, Femi, 08069847638, Ogun 64
66
ADDING COLUMN TO TABLE
Example:
67
ALTER A RECORD
• The UPDATE keyword is used for altering the content of a record
• To alter the stname and AdmNo in row 1:
UPDATE abc SET Stname='Fred', ADMNO =5454 WHERE
Stname='Felix';
68
CREATE THE TABLES BELOW USING
SQL
DATABASE NAME: EMPLOYEE
Employee
Company
EmpId
Name
FirstName
Address
LastName
City
Address
Phone
Phone
State
Company
HireDate
City 69
JobTitle
SOME TASKS
70
CREATE THE TABLE BELOW USING
SQL. DATABASE NAME IS
STUDENTDB. TABLE NAME IS
STSCORE
ExamNum FirstName LastName Score
73
SOLUTION
CREATE TABLE Product(Serial_no INT Primary Key,
Product VarChar(10) NOT NULL,
Price Currency,
Date_delivered DateTime);
OR
CREATE TABLE Product(Serial_no INT Primary Key,
Product VarChar(10) NOT NULL,
Price Money,
Date_delivered DateTime);
74
Fill in the missing commands in the SQL code
Answer:
CREATE TABLE StudentData(StdID INT Primary key)
75
MANUALLY CREATE THE TABLE
BELOW
Customer CustomerNa Phone State Countr
ID me y
Cust_1 Garba 090746346 Borno Nigeria
2
Cust_2 Brown 276173827 Londo Uk
8 n
Cust_3 Jersey 984938234 Ashant Ghana
2 i
Cust_4 Dele 080273627 Lagos Nigeria
3
77
DATABASE SECURITY
85
TYPES OF DATABASE SECURITY
CONTROL
• Many layers and types of information security control are
appropriate to databases, including:
• Access control
• Database Auditing
• Authentication
• Encryption
• Integrity controls
• Backups
• Application security Topic: Database Security
At the end of this topic students should
be able to
1) Define database security; 86
database.
DAC
• Users have privileges to access or modify objects in the database. If
they have permission, users can grant their privileges to other users.
• Allows an individual complete control over any object they own.
• There are two important concepts in DAC:
1. File and data ownership- every object has an owner. The access
policy to this object is determined by its owner.
2. Access rights permissions:- This is the control that an owner can
assign to other objects for specific resources.
• E.g. Facebook share – You can specify who gains access to resources
you create.
• How will the authorised user be able to read the encrypted data?
94
BACKUP
• This refers to creating a copy or archiving of the data
that exist in the database outside the database.
• Such backup becomes useful to restore the database in
case of data loss or system crash.
• Backups can be automated to run at a particular time or
done manually.
Tutorial Question:
• Outline 5 situations where data backup will prove
useful.
Define
101
ASSIGNMENT
WHAT IS A COMMITTED
TRANSACTION IN DATABASE?
STATE EXAMPLES.
102
TUTORIAL QUESTION
• Make a note on ACID wrt databases.
• More information at
• www.techopedia.com/definition/16/commit
108
QUESTIONS
109
QUERY BY EXAMPLE (QBE)
• Query by example (QBE) is a query method implemented in
most database systems, most notably for relational databases.
• It is a graphical query language where users can input
commands into a table like conditions and example elements.
• In the background, the user’s operations are transformed into a
database manipulation language such as SQL, and it is this SQL
statement that will be executed in the background.
110
QUERY BY EXAMPLE (QBE)
• Do your query from design view
• Run the query
• Right click on the query tab
• And select View SQL
111
PRACTICAL TASK
• Open MS Access and create a database named “Yourname-
QBE”
• Create a table with the following data or similar and data
types:
CA1
ADM_NUM STNAME Act1 Act2
CLASS (text) Test (Number)
(text) (Text) (Number) (Number)
18/2136 Okedele SS3A 20 20 19
18/2190 Ojo SS3A 18 15 7
18/2224 Golibe SS3A 20 5 8
112
QBE PRACTICE TASK
• Enter the following into a database.
• Generate the total using QBE.
• Use QBE to display only those whose scores are greater than 30
in the result-set.
CA total
ADM_NUM STNAME CLASS CA1 CA2
(text) (Text) (text) (Number) (Number)
18/2136 Okedele SS3A 20 20
113
INTEGRITY CONSTRAINTS OVER
RELATION
• The data stored in a database must satisfy certain
consistency constraints.
• Example: The scores of a student cannot be a negative
value.
• This can be defined so that it is checked every time the
database is updated.
114
1. ENTITY INTEGRITY
• Entity integrity rule states that every table must have a
primary key and that the column or columns chosen as
primary key must be unique and not NULL.
115
2. DOMAIN INTEGRITY
• Domain integrity specifies that all columns in a relational
database must be declared upon a defined domain.
• A domain is a set of values of the same type.
• It is the validity of entries for a given column. This is done by
restricting the data type, data format or range of possible values
(through foreign constraints, Check constraints, DEFAULT
definitions, NOT NULL definitions, and rules)
116
3. REFERENTIAL INTEGRITY
• This preserves the defined relationships between tables when
records are inserted or deleted.
• Example: there is a foreign key value without a corresponding
primary key value in the referenced table. Record 2 in the second
table has no link to the primary table. The record existed but was
deleted. If referential integrity was enforced, this would not have
taken place.
Artist_Id Artist_name
3 Greens 4 2 Pluto
5 3 Gadget
5 Henry
117
COMPUTER SECURITY
118