You are on page 1of 47

Normalisation

05/09/2023 ICT Department


Normalisation

• Normal Form is a way of structuring data in a relational


database according to formal rules, in order to avoid problems
of efficiency and security in accessing and maintaining the
data.

05/09/2023 ICT Department


Normalisation

• One of the key reasons for performing normalisation is that


without it your data stored in the database will lose its
integrity.
• This happens as, in un-normalised databases, data anomalies
occur due to too much redundancy in the database structure.

05/09/2023 ICT Department


Anomalies

Course_ID Course_Name Course_Teacher Class_Room Room_Size

4673 A’ Level S McLaughlin D109 27

2364 GCSE E. Kivlehan D110 27

8237 KS3 M. Leonard D108 27

2364 GCSE E. Kivlehan D110 27

05/09/2023 ICT Department


Update Anomalies

• This occurs where data that repeats in multiple records is


changed in one record, but not all the records.

05/09/2023 ICT Department


Update Anomalies

• For example, in the previous Course_Name Course_Teacher

table, if we were to update the A’ Level S McLaughlin


teacher of GCSE to S. Hamilton 1st instance

GCSE S. Hamilton
for the first instance, we may
KS3 M. Leonard
forget to update the second 2nd
instance
instance of this. GCSE E. Kivlehan

05/09/2023 ICT Department


Insertion Anomalies

• This occurs where you need to insert data into a table, but
cannot as there are fields that require values you don’t
currently have.
• For example, if we were to add a new course but haven’t
assigned a teacher or classroom yet, there would be a lot of
missing data.
05/09/2023 ICT Department
Deletion Anomalies

• This occurs where we delete unwanted data, which causes data


we still require to be deleted with it.
• Such as in the previous table, if we deleted the course 4673,
we’d lose the data on the classroom, such as the size of the
room.

05/09/2023 ICT Department


Un-normalised Data
OrderNo AccNo Customer Address1 Date ItemNo Item Qty ItemPrice

3479 83 Bro. Partners 46 Estate Dr. 28/09/19 02 Cheese 12 £1.00

3479 83 Bro. Partners 46 Estate Dr. 28/09/19 01 Ham 6 £1.20

2332 92 Fligen Co. 12 Custer St. 28/09/19 03 Club 25 £1.35

3214 101 Profix Direct 86 Collins Av. 29/09/19 04 BLT 12 £1.40

3214 101 Profix Direct 86 Collins Av. 29/09/19 05 Salad 2 £0.90

3214 101 Profix Direct 86 Collins Av. 29/09/19 01 Ham 8 £1.20

05/09/2023 ICT Department


Identify the
First Normal Form (1NF)
Identify the
Non- Repeating
repeating group
group

OrderNo AccNo Customer Address1 Date ItemNo Item Qty ItemPrice

3479 83 Bro. Partners 46 Estate Dr. 28/09/19 02 Cheese 12 £1.00

3479 83 Bro. Partners 46 Estate Dr. 28/09/19 01 Ham 6 £1.20

2332 92 Fligen Co. 12 Custer St. 28/09/19 03 Club 25 £1.35

3214 101 Profix Direct 86 Collins Av. 29/09/19 04 BLT 12 £1.40

3214 101 Profix Direct 86 Collins Av. 29/09/19 05 Salad 2 £0.90

3214 101 Profix Direct 86 Collins Av. 29/09/19 01 Ham 8 £1.20

05/09/2023 ICT Department


1NF

• Create two tables/entities:


– 1 for non-repeating group; and
– 1 for repeating group.

05/09/2023 ICT Department


1NF – Non-repeating (when normalised
you only need to enter the data once)
OrderNo AccNo Customer Address1 Date

3479 83 Bro. Partners 46 Estate Dr. 28/09/19

2332 92 Fligen Co. 12 Custer St. 28/09/19

3214 101 Profix Direct 86 Collins Av. 29/09/19

05/09/2023 ICT Department


1NF – Non-repeating

• Identify a primary key field for your non-repeating table


• This key field must be able to uniquely identify a record
OrderNo AccNo Customer Address1 Date

3479 83 Bro. Partners 46 Estate Dr. 28/09/19

2332 92 Fligen Co. 12 Custer St. 28/09/19

3214 101 Profix Direct 86 Collins Av. 29/09/19

05/09/2023 ICT Department


1NF – Repeating (once normalised this
data can appear multiple times)
ItemNo Item Qty ItemPrice

02 Cheese 12 £1.00

01 Ham 6 £1.20
03 Club 25 £1.35

04 BLT 12 £1.40

05 Salad 2 £0.90

01 Ham 8 £1.20

05/09/2023 ICT Department


1NF – Creating a relationship
• In order to create a OrderNo ItemNo Item Qty ItemPrice

relationship between the 3479 02 Cheese 12 £1.00

two tables, the primary 3479 01 Ham 6 £1.20

key from the non- 2332 03 Club 25 £1.35

3214 04 BLT 12 £1.40


repeating table must be
3214 05 Salad 2 £0.90
added to the repeating
3214 01 Ham 8 £1.20
table
05/09/2023 ICT Department
INF – Repeating

• Identify a composite OrderNo ItemNo Item Qty ItemPrice

key for your repeating 3479 02 Cheese 12 £1.00

3479 01 Ham 6 £1.20


table
2332 03 Club 25 £1.35
• These fields when used
3214 04 BLT 12 £1.40
together, must uniquely 3214 05 Salad 2 £0.90

identify a record 3214 01 Ham 8 £1.20

05/09/2023 ICT Department


INF – Final tables

• Each table need to be assigned a relevant table name and


written out in the following format:
– tblOrder (OrderNo, AccNo, Customer, Address1, Date)
– tblOrderItem (OrderNo, ItemNo, Item, Qty, ItemPrice)

05/09/2023 ICT Department


1. Normalise the following to 1NF
StudentID StudentName SubjectID Subject TutorID Tutor ExamResult
0123 Adams C E05 ICT 31 Mrs Leonard Distinction
0123 Adams C E06 SSD 20 Mrs McLaughlin Pass
0114 Jones P E12 DT 28 Miss Kivlehan Merit
0114 Jones P E06 SSD 20 Mrs McLaughlin Distinction
0211 Moore R E12 DT 28 Miss Kivlehan Distinction
0211 Moore R E06 SSD 20 Mrs McLaughlin Distinction
0211 Moore R E05 ICT 31 Mrs Leonard Distinction

05/09/2023 ICT Department


2. Normalise the following to 1NF
StudentID StudentName CourseID CourseTitle BookID BookTitle LoanDate ReturnDate

S123 Green C5 GCSE B234 ICT Theory 01/07/19 07/07/19

S123 Green C5 GCSE B452 ICT Projects 01/07/19 05/07/19

S123 Green C5 GCSE B231 DBMS 02/07/19 10/07/19

S124 Brown C5 GCSE B231 DBMS 01/06/15 09/06/19

S124 Brown C5 GCSE B534 Maths 02/07/19 09/07/19

S125 Grey C6 GCE B734 DFDs 02/07/19 11/07/19

S125 Grey C6 GCE B231 DBMS 05/08/19 10/08/19

05/09/2023 ICT Department


3. Normalise the following to 1NF
TeamID TeamName EmployeeID EmployeeName DeptID DeptName
T001 Sales E021 Green D011 Marketing
E036 Plum D011 Marketing
E034 Brown D012 IT
E045 Black D012 IT
E056 White D013 Finance
T002 Research E021 Green D011 Marketing
E022 Grey D012 IT
E045 Black D012 IT
E056 White D013 Finance

05/09/2023 ICT Department


4. Normalise the following to 1NF
LoanID CustomerID CustomerName Address LoanDate Total Cost PlantID PlantName Qty
501 Bay Tree 10
1001 102 Green Belfast 02/05/19 £50
503 Fern 4
1002 104 White Lisburn 03/05/19 £25 503 Fern 3
503 Fern 4
1003 103 Brown Lisburn 03/05/19 £75 501 Bay Tree 2
504 Rose 4
504 Rose 10
1004 102 Green Belfast 03/05/19 £35
503 Fern 2

05/09/2023 ICT Department


5. Normalise the following to 1NF
InvoiceID InvoiceDate CustomerID Name Address ItemID Description UnitPrice Qty

M8765 Motherboard £36.99 1

12345 02/05/19 C3215 Green 12a Old Row H3921 External HD £52.99 2
Belfast
P6124 Power supply £57.99 1

05/09/2023 ICT Department


6. Normalise the following to 1NF
ProjectID Project ClientID Client ProgrammerID Programmer Job
PR6 Green Coding
P23 Holiday MIS C19 Flinego PR19 Black Testing
PR2 Gray Coding

P44 Books DB C24 Reedar PR3 White Testing


es PR19 Black Coding

05/09/2023 ICT Department


7. Normalise the following to 1NF
FlightID AirportCode Airport Date Departure Arrival PassengerID Name Contact
XYZ123 DUB Dublin 01/11 09:15 09:45 C3458 Smith 909090
XYZ123 DUB Dublin 01/11 09:15 09:45 C8764 Jones 919191
XYZ123 DUB Dublin 01/11 09:15 09:45 C1382 Green 909190

05/09/2023 ICT Department


Second Normal Form (2NF)

• Second Normal Form eliminates functional dependencies on a


partial key by putting the fields in a separate table from those
that are dependent on the whole key.
• Only tables with composite keys are amended at this time.

05/09/2023 ICT Department


2NF – Functional Dependencies

• Look at the non-key OrderNo ItemNo Item Qty ItemPrice


fields (Item, Qty & 3479 02 Cheese 12 £1.00
Price) to see if they’re
3479 01 Ham 6 £1.20
functionally dependent
on both parts of the 2332 03 Club 25 £1.35

composite key. 3214 04 BLT 12 £1.40

3214 05 Salad 2 £0.90

3214 01 Ham 8 £1.20

05/09/2023 ICT Department


2NF – Functional Dependencies
• Item - This This is NOT OrderNo ItemNo Item Qty ItemPrice
functionally dependent.
• This is the item description 3479 02 Cheese 12 £1.00

and stays the same in 3479 01 Ham 6 £1.20


every order, so it is not 2332 03 Club 25 £1.35
dependent on the
OrderNo field. 3214 04 BLT 12 £1.40

• Therefore, it must be 3214 05 Salad 2 £0.90


placed in a new table. 3214 01 Ham 8 £1.20

05/09/2023 ICT Department


2NF – Functional Dependencies

• Qty - This is OrderNo ItemNo Item Qty ItemPrice


functionally dependent 3479 02 Cheese 12 £1.00
on both parts, it is the
3479 01 Ham 6 £1.20
quantity of each item
in each order. 2332 03 Club 25 £1.35

• Therefore, Qty stays in 3214 04 BLT 12 £1.40

this table. 3214 05 Salad 2 £0.90

3214 01 Ham 8 £1.20

05/09/2023 ICT Department


2NF – Functional Dependencies
• ItemPrice - This is NOT OrderNo ItemNo Item Qty ItemPrice
functionally dependent.
3479 02 Cheese 12 £1.00
• This is the price of the
item and stays the same 3479 01 Ham 6 £1.20

in every order, so it is not 2332 03 Club 25 £1.35

dependent on the 3214 04 BLT 12 £1.40


OrderNo field. 3214 05 Salad 2 £0.90
• Therefore, it must be
3214 01 Ham 8 £1.20
placed in a new table.
05/09/2023 ICT Department
2NF – Creating a new table/entity

• Remove the non- OrderNo ItemNo Qty

functional field(s) 3479 02 12

3479 01 6
(e.g. Item &
2332 03 25
ItemPrice) from the
3214 04 12
table. 3214 05 2

3214 01 8

05/09/2023 ICT Department


2NF – Creating a new table/entity

• Place the key field that the ItemNo Item ItemPrice

removed field(s) (Item & 02 Cheese £1.00


01 Ham £1.20
ItemPrice) is dependent on
03 Club £1.35
(Item) into a new table.
04 BLT £1.40
• Place the removed field(s) into 05 Salad £0.90
the table also. 01 Ham £1.20

05/09/2023 ICT Department


2NF – Primary Key

• Identify a primary key field for ItemNo Item ItemPrice

the new table 02 Cheese £1.00


01 Ham £1.20
• This will be the part of the
03 Club £1.35
composite key you have taken
04 BLT £1.40
from the repeating table 05 Salad £0.90
(ItemNo). 01 Ham £1.20

05/09/2023 ICT Department


2NF – Final tables

• The new table needs to be assigned a relevant table name and


each table must be written out in the following format:
– tblOrder (OrderNo, AccNo, Customer, Address1, Date)
– tblOrderItem (OrderNo, ItemNo, Qty)
– tblItem (ItemNo, Item, ItemPrice)

05/09/2023 ICT Department


Normalise to 2NF

• Continue the normalisation process for the previous 7


questions – normalising each to 2NF

05/09/2023 ICT Department


Third Normal Form (3NF)

• Third Normal Form eliminates functional dependencies on


non-key fields by putting them in a separate table.
• Only tables with two or more non-key fields are amended at
this time.

05/09/2023 ICT Department


3NF

• At this stage we focus on our non-key fields

OrderNo AccNo Customer Address1 Date

3479 83 Bro. Partners 46 Estate Dr. 28/09/19

2332 92 Fligen Co. 12 Custer St. 28/09/19

3214 101 Profix Direct 86 Collins Av. 29/09/19

05/09/2023 ICT Department


3NF – identifying a potential key field
• Identify any non-key field that could potentially be a key field
in a new table.
• Tip: it has to be unique, usually a number or ID
OrderNo AccNo Customer Address1 Date

3479 83 Bro. Partners 46 Estate Dr. 28/09/19

2332 92 Fligen Co. 12 Custer St. 28/09/19

3214 101 Profix Direct 86 Collins Av. 29/09/19

05/09/2023 ICT Department


3NF – Identifying fields for new table

• Identify which non-key fields should be placed in the new table


• Which fields are dependent on the new key field?
OrderNo AccNo Customer Address1 Date

3479 83 Bro. Partners 46 Estate Dr. 28/09/19

2332 92 Fligen Co. 12 Custer St. 28/09/19

3214 101 Profix Direct 86 Collins Av. 29/09/19

05/09/2023 ICT Department


3NF – Creating a new table

• Move the relevant field to the new table


AccNo Customer Address1

83 Bro. Partners 46 Estate Dr.

92 Fligen Co. 12 Custer St.

101 Profix Direct 86 Collins Av.

05/09/2023 ICT Department


3NF – Creating a Relationship

• To create a relationship between the two table, leave the


primary key from the new table, in the existing table
OrderNo AccNo Date

3479 83 28/09/19

2332 92 28/09/19

3214 101 29/09/19

05/09/2023 ICT Department


3NF – Final tables

• The new table needs to be assigned a relevant table name and


each table must be written out in the following format:
– tblOrder (OrderNo, AccNo, Date)
– tblAccount (AccNo, Customer, Address1)
– tblOrderItem (OrderNo, ItemNo, Qty)
– tblItem (ItemNo, Item, ItemPrice)

05/09/2023 ICT Department


Normalise to 3NF

• Continue the normalisation process for the previous 7


questions – normalising each to 3NF

05/09/2023 ICT Department


ER Diagram

• The main purpose of an Entity Relationship model is to


identify:
– what data is stored on the system;
– what data is processed on the system; and
– how the data is organised.

05/09/2023 ICT Department


ER Diagram
 

One to one (1:1)  


   

relationship
 

One to many (1:M)  


   

relationship
 

Many to many (M:M)  


   

relationship
05/09/2023 ICT Department
ER Diagram

The many symbols ALWAYS goes into your composite key table

tblOrder tblOrderItem tblItem

The owner of an account can make many orders


Each order belongs to one account

tblAccount

05/09/2023 ICT Department


ER Diagrams

• Draw ER Diagrams for the previous 7 questions

05/09/2023 ICT Department


8. Normalise to 3NF and Draw ER Diagram
Course Course Tutor Tutor Student Student Student
ID Title ID Name ID Name DOB Status Result

C1 Dig Tech T1 Babbage S3 Green 01/01/01 Full-time Pass


C1 Dig Tech T1 Babbage S5 White 04/02/01 Part-time Merit
C4 Maths T2 Turing S7 Black 12/02/01 Full-time Pass
C4 Maths T2 Turing S3 Green 01/01/01 Full-time Merit
C7 Prog T1 Babbage S8 Gray 12/03/01 Part-time Pass
C9 ICT T3 Pascal S3 Green 01/02/01 Full-time Pass

05/09/2023 ICT Department

You might also like