+ All Categories
Home > Documents > Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Date post: 15-Jan-2016
Category:
View: 215 times
Download: 0 times
Share this document with a friend
36
Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation
Transcript
Page 1: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Database Design Concepts

Lecture 19 Term 2 week 8Worked example of normalisation

Page 2: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Objectives

In this lecture we will introduce the process of normalisation.Through using a worked example we will introduce the concepts of 1st Normal From 2nd normal Form 3rd Normal Form

Page 3: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Step by step plan to normalisation

Investigate the users requirements Use documents ( there may be

several)

Page 4: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.
Page 5: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Identify the attributes from the form

List attributesBooking reference number Flight numberCustomer name DirectionCustomer Address Operator

Phone Arrival timeVilla name Departure airportAddress number of passengers costDestination TotalStart dateCost Total CostEnd Date

Page 6: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Give attributes a full name. Identify groups of data which repeat by adding bracketsAdd any missing attributes ( in this case weekly cost of villa)

Booking reference numberCustomer NameCustomer Address(Customer Phone)Villa nameVilla AddressStart DateEnd DateCost of villaWeekly cost of villa

A customer can have more than one phone number

Page 7: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

These are all contained in a bracket because they will repeat as a group together. These are usually shown on a form as a table

(DirectionFlight numberOperatorArrival TimeDeparture airportNumber of PassengersCost of FlightTotal cost of flight)Total cost of holiday

Page 8: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Find a keyWe need to check all the attributes to identify a unique identifier This is an attribute which will uniquely identify what the table is showing. It is usually a number.There will be no other row with this value in the key field.

In this case booking reference numberIf there is no key field you may need to add one. Name the table BookingName any column that can have multiple values by creating a new attribute. In this case Customer phone number 2

Page 9: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Normally we show the table like this

Booking( Bookingreferencenumber,customer name,customer address, customer phone, Customer phone2, villa name, villa address, destination, start date of holiday, end date of holiday,weekly cost of villa, villa cost for holiday,(Flight number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight), total cost of holiday)

Repeating

group

Added attribut

e

Named column

Table name Unique identifier

Page 10: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

We are now ready to normalise

Summary so far List all attributes from source document(s) Give all attributes their full name Create extra attributes for attributes which

may have may have several values eg Phones

Add any obvious missing attributes Show repeating groups in brackets Identify the unique identifier if there is one Add a unique identifier if necessary Name table- in this case booking

Page 11: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

First normal formRemove repeating groups

Identify each repeating group. In this case the group with flight numberFor each group Remove the attributes of the

repeating group from the existing table to a new table

Page 12: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

(Flight number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight)

LeavingBooking( Bookingreferencenumber,

customer name,customer address, customer phone, Customer phone2, villa name, villa address, destination, start date of holiday, end date of holiday,weekly cost of villa, villa cost for holidaytotal cost of holiday)

Booking( Bookingreferencenumber,customer name,customer address,customer phone, Customer phone2, villa name, villa address, destination, start date of holiday, end date of holiday,weekly cost of villa, villa cost for holiday,(Flight number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight), total cost of holiday)

Page 13: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

This becomes a new table

Place the attributes in brackets As it is a new table - give it a name

(bookedFlights) Add the unique identifier from the

original table to the new table ( as a foreign key- Booking reference number)

Identify a unique identifier for the new table-

Page 14: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Creating a unique identifier

This could be A composite key

Made up of the foreign key and another attribute from the table. These two (or more) attributes uniquely identify any row of the table

OR An entirely new attribute added to the

table

Page 15: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

In this example

Flight number appears a good idea It is a number ( key fields are often numbers- but

not always)

HoweverIs it possible for more than one record in the table to have the same flight number?So it is not uniqueHowever could a booking have the same flight number more than once?So Booking reference number and flight number would be unique- A composite key

Page 16: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Unique identifier- the

whole lot

Booked flights(Flight number, booking reference number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight,)

Repeat process for any other repeating groups –none in this case.

Name of Table

Unique identifier of

original table

Page 17: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Second Normal FormAll attributes in the table must be determined by the whole unique identifier

Take each table with a composite unique identifier and check each attribute can only determined from the unique identifier- Consider what we did last weekIn other words is the value of the attribute associated with the value in the identifier or just one part of it

Page 18: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Starting with the flight table

Booked Flight (Booking reference number, Flight number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight)Eg is direction determined by the whole key or part of it? Do I need to know the booking reference number

and the flight number? The flight number only Or Booking reference number only

To know the direction of the flight

Page 19: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Direction is determined by the flight number onlyWork through the attributes individually in this way remembering which part of the key they are dependant on.

Draw the functional determinancy diagram

Page 20: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

DirectionOperatorDeparture airportFlight TimeArrival TimeNumber of PassengersCost of flightTotal cost of flight

Determined by flight number only

Page 21: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Booking reference no

Flight no

Total cost

No of passengers

Direction

Operator

Departure Airport

Flight timeArrival time

Cost of flight

Page 22: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Remove these attributes from the tablePlace all attributes that are dependant on on part of the key in a table together. Give the table a name.Add a unique identifier – this will be the attribute they are dependant on.This becomes-

Page 23: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

This will create a new table

flights(flight number,direction, operator, departure airport, flight time, arrival time, cost of flight)

All the attributes removed were dependant on the same attribute so are all in the same table

There are no more tables with composites

Page 24: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

The booked flight table now looks like this.

BookedFlight (Booking reference number, Flight number, number of passengers, total cost for flight)

Check the names of the old table to check it is still sensible

Page 25: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Third normal formRemove transitive dependencies

Transitive dependency is when an attribute can be determined by a non key attribute/unique identifier

Identify them and the non-key attribute they are dependant on

For each table ( which does not have a composite key) check for transitive dependency

Page 26: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Booking table

Booking (Booking reference number,customer name,customer address, customer phone, customer phone2,villa name, villa address, destination, start date of holiday, end date of holiday,weekly cost of villa, villa cost for holiday,total cost of holiday)

Customer address is determined by the customers name ie a customer name will have one customer address associated with it.

Continue through the remaining attributesDraw the functional determinancy table

Page 27: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Customer name DestinationVilla name ?

Customer Address- customer name

Start date of holidayBooking Reference Number

Customer phoneCustomer name

End date of holidayBooking reference number

Customer phone 2Customer name

Weekly cost of villa- booking reference number

Villa name Villa cost of holidayBooking reference number

Villa addressVilla name

Total cost of holidayBooking reference number

Page 28: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Booking (Booking reference number,customer name,customer address, customer phone, customer phone 2,villa name, villa address, destination, start date of holiday, end date of holiday,weekly cost of villa, villa cost for holiday,total cost of holiday)

1 Remove from the table into tables for each grouping (two tables),

2. Add the attribute they are dependant on.3. Identify a unique identifier for the new

table(s)4. Put the unique identifier in the original

table ( As a foreign key)5. Give the new table(s) a name.

Page 29: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Booking reference

no

Customer name

Villa name

Start date of holiday

End date of holiday

Villa cost of holiday

Total cost of holiday

Customer address

Customer phone

Customer phone 2

Villa address

Destination

Weekly cost of villa

Page 30: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

( customer name, customer address, customer phone, customer phone2)

Are any of these attributes unique?We could have two customers with the same

Name Address Phone number

None are unique so add a new attribute- Customer number as the key/unique identifierName the table, add customer number to the original booking table

Page 31: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

(villa name, villa address, destination,)

Are any of these attributes unique?We could have two villas with the same

Name Address ( unlikely but possible)

None are unique so add a new attribute- Villa number as the key/unique identifierName the table, add villa number to the original booking table

Page 32: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Booking (Booking reference number,customer number, villa number, start date of holiday, end date of holiday,,villa cost for holiday,total cost of holiday

Customer(customer number , Customer name,customer address, customer phone, customer phone2)

Villa(Villa number, villa name, villa address, destination, weekly cost of villa)

Page 33: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Check flights and booked flights- these have no transitive dependancies

Page 34: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Finally remove calculated attributes if you wish

Booking (Booking reference number, customer number, villa number, start date of holiday, end date of holiday, villa cost for holiday, total cost of holiday

Customer(customer number, customer name,customer address, customer phone, customer phone 2)

Villa(villa number, villa name, villa address, weekly cost of villa, destination,)

Booked Flight (Booking reference number, Flight number, number of passengers, total cost for flight,)

flights(flight number,direction,operator, departure airport, flight time, arrival time, cost of flight)

Page 35: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Fully normalised Tables

Booking (Booking reference number, customer number, villa number, start date of holiday, end date of holiday, villa cost for holiday)

Customer(customer number, customer name,customer address, customer phone, customer phone 2)

Villa(villa number, villa name, villa address, weekly cost of villa,destination,)

Flight (Booking reference number, Flight number, direction, number of passengers, total cost for flight)

Booked flights(flight number,operator, departure airport, flight time, arrival time, cost of flight)

Page 36: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation.

Summary

We have completed an example.You should be able to split tables to comply with the rules of 1st, 2nd

and 3rd normal form. Identify appropriate unique identifiers Ensure foreign keys are present to create links

This will remove redundancy, repeating groups as well as column and row order significance.You will do some examples in the tutorials.


Recommended