0% found this document useful (0 votes)
17 views50 pages

Lecture Week 4 Normalisation Voice Over

Uploaded by

camille
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views50 pages

Lecture Week 4 Normalisation Voice Over

Uploaded by

camille
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

Database Design and Implementation

MOD002589

Lecture 4
Normalisation
Dr. Arooj Fatima
Demo
&
Submission
Week12

Week11
Get Week10
Feedback
on your
Week9
design Week8
Week7
Week6
Week5
ation
evalu
tion,
enta
, Implem
n
Desig

elling
Mod

Week1: Introduction to the learning Outcomes and module


DATABASE DEVELOPMENT LIFECYCLE
n ts 1
me
ire
e qu
e wR
N
G et
5 2

Database
Development
Lifecycle
3
4
RECAP: WEEK 1 – REQUIREMENT ANALYSIS

Activity: Requirement Analysis

Output: Entities and Attributes

For example for a take-away system like just-eat.co.uk

Entities: Customers, Restaurants, Owners, Menus, Foods, Orders

AND maybe

Cities, Deals, Delivery_Types, Postcodes etc.

Attributes for Customers: first_name, last_name, email…


RECAP: WEEK 2 – ER-MODEL

0..* 1..*
1..1 0..*

1..*
1..*

1..*
1..1

0..*
1..1
RECAP: WEEK 3 – EERD-MODEL

• Extended attributes (composites, derived, single valued, multi-


valued)

• Generalisation, composition and aggregation

• Participation constraints

• Week and strong entities


PREVIOUSLY…
Requirement Analysis
- analysis and observation of existing systems

Database Design/Modelling
- ER-Model
- EERD
- Normalisation
NORMALISATION
MAPPING WITH LEARNING OUTCOMES

LO1: Link the flow of activity in the sequence of capturing the


state of the real world in terms of data

LO2: Model data, and the prescriptive translation of that model to


data constructs for machine purposes.
MAPPING WITH ASSIGNMENT
Requirements Analysis 15%

Design / Modelling 25%

Implementation 10%

Testing Queries 50%


NORMALISATION
Normalisation is a database design technique that begins by
examining relationships between attributes (Connolly and Beg,
2015, p.451).

Normalisation can be used as a stand-alone technique.

OR

Normalisation can be used in combination with ER-Model to


validate the database design.
WHAT DOES NORMALISATION DO?

 Cross-checks the more creative ERD approach

 Ensures all data is captured

 Ensures all entities are spotted

 Validate data is not redundant


PROBLEMS WITH UN-NORMALISATION DB

If a table is not properly normalized and have data


redundancy then it will

eat up extra memory space

make it difficult to handle and update the database

Insertion, Updation and Deletion Anomalies are very


frequent if database is not normalized.
HOW TO DO NORMALISATION?

There are following stages of normalisation

First normal form (1NF)

Second normal form (2NF)

Third normal form (3NF)

Higher normal forms


NORMAL FORMS
SOME CONCEPTS WE SHOULD
KNOW
Student (Entity) - Table
Attributes / Columns

Student_id First_name Last_name

123456 Maria Shams

123457 John Doe

Records / Tuples
123458 … ….

123459 …. …
FIRST NORMAL FORM (1NF)
An entity is in 1NF if, and only if, it has an
identifying key and there are no repeating
attributes or groups of attributes.
FIRST NORMAL FORM (1NF)
Product

Product_id Product_title Colour Price

1 XYZ Black, Yellow 19.25

2 ABC Green, Blue, Red 5.00

1NF Failed
FIRST NORMAL FORM (1NF)
Product Product_colours
Product_id Product_title Price Product_id Colour

1 XYZ 19.25 1 Black

2 ABC 5.00 1 Yellow

1NF Passed
SECOND NORMAL FORM (2NF)
An entity is in 2NF if, and only if, it is in 1NF
and has no attributes which require only
part of the key to identify them uniquely.
SECOND NORMAL FORM (2NF)
Orders
Customer_id Store_id Store_location Order_price …

1 1 Cambridge 120 …

1 2 London 45 …

2NF Failed – location depends upon Store_id only


SECOND NORMAL FORM (2NF)
Orders Stores
Customer_id Store_id … Store_id Store_location

1 1 … 1 Cambridge

1 2 …. 2 London

2NF Passed
THIRD NORMAL FORM (3NF)
An entity is in 3NF if, and only if, it is in
2NF and no non-key attribute depends on
any other non-key attribute.
THIRD NORMAL FORM (3NF)
Products
Product_id Category_id Category_descriptio Product_title Price
n

1 1 kitchen XYZ 19.25

2 2 garden ABC 5.00

3NF Failed – category_description depends upon category_id (non key)


THIRD NORMAL FORM (3NF)
Products Categories
Product_id Category_id Product_title Price Category_id Category_descriptio
n

1 1 XYZ 19.25 1 kitchen

2 2 ABC 5.00 2 garden

3NF Passed
A QUICK EXAMPLE
Online Take-away
REQUIREMENT ANALYSIS
Entities & Attributes
ER-MODEL - Relations
ER-MODEL - Add Primary and Foreign Keys

Primary Key
order
customer_ID {FK}
ER-MODEL - Extend Attributes

order
customer_ID {FK}

Composite
Attribute
multiple
EERD
order
customer_ID {FK}

Aggregation
Composition
EERD – find errors
order
customer_ID {FK}

Is this correct
to have
restaurant ID
as Foreign key
here?

Is this relation
correct
between food
and
customer?
EERD – find errors - solution
order
customer_ID {FK}

A many to
many
relationship Remove
needs to be this
sorted using relation
a linking
entity.

Remove this key


NORMAL FORMS
FIRST NORMAL FORM (1NF)
An entity is in 1NF if, and only if, it has an
identifying key and there are no repeating
attributes or groups of attributes.

Repeat for each entity


FIRST NORMAL FORM (1NF)
Customers
customer_ID first_name Last_name … favourite_restaurants

1 Loki Wijnen … 1,2

2 David Dunhill … 1,2,4

1NF Failed
Note the relation: one customer may like many restaurants and one restaurant
may be liked by many customers.
FIRST NORMAL FORM (1NF)
Customers Favourites
customer_ID first_name Last_name … customer_ID favourite_restaurant

1 Loki Wijnen … 1 1

2 David Dunhill … 1 2

1NF Passed
SECOND NORMAL FORM (2NF)
An entity is in 2NF if, and only if, it is in 1NF
and has no attributes which require only
part of the key to identify them uniquely.
SECOND NORMAL FORM (2NF)
Reviews
Restaurant_id Customer_id Customer_name rating comment

1 45 John 4.0 Good Food

1 23 Jamie 4.5 Excellent

2NF Failed – customer_name depends upon customer_id only


SECOND NORMAL FORM (2NF)
Reviews
Restaurant_id Customer_id rating comment

1 45 4.0 Good Food

1 23 4.5 Excellent

2NF Passed
Removed customer_name column. Since we already have Customers table, we don’t
have to create it.
THIRD NORMAL FORM (3NF)
An entity is in 3NF if, and only if, it is in
2NF and no non-key attribute depends on
any other non-key attribute.
FIRST NORMAL FORM (3NF)
Restaurant

restaurant_ID name contact street_name post_code owner_name owner_contact

1 KFC 012334567 East Road CB1 1PT John Doe 01233890

2 Peppy’s 012334567 East Road CB1 1PT John Doe 01233890

3NF Failed
FIRST NORMAL FORM (3NF)
Restaurants Owners
restaurant_ID name contact street_nam post_code owner_ID Owner_ID owner_name owner_contact
e

1 KFC 012334567 East Road CB1 1PT 1 1 John Doe 01233890

2 Peppy’s 012334567 East Road CB1 1PT 1 2 ABC 01233234

3NF Passed
Note the relation: one restaurant can have one owner only.
order

Solved many to many relation


Can you spot a missing relation in the diagram?

order
Can you spot a missing relation in the diagram?

order

serving_price
has been
added here to
store the
price at the
time of order.
The serving
price may
change in the
parent table
but not here.
CHECK-LIST
While using normalisation as evaluation methodology, make sure you
checked the followings

There are no many-to-many relationships between any two entities


All linked entities have relevant Foreign Keys

For each individual entity


Each entity has a primary key
There are no multi-valued attributes left to be taken care of
There are no redundant attributes
All normal forms are met
READING LIST FOR THIS WEEK
Complete Reading List

Chapter 14:

Normalisation

Sixth Edition Available at ARU Library (online and hard copy)


REFERENCES
 Connolly, T.M. Begg, C., 2015. Database Systems : practical approach to
design, implementation, and management. [e-book] Sixth edition, Global
edition.. ed. Harlow : Pearson Education Limited. Available through: Primo.
Figure : Source (Office Online Resources) | License

ANY QUESTIONS?

You might also like