database design concepts lecture 19 term 2 week 8 worked example of normalisation
Post on 15-Jan-2016
218 views
TRANSCRIPT
![Page 1: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/1.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/4.jpg)
![Page 5: Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/12.jpg)
(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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/19.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/20.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/21.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/22.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/23.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/24.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/25.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/26.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/27.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/28.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/29.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/30.jpg)
( 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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/31.jpg)
(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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/32.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/33.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/34.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/35.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022062518/56649d595503460f94a389a0/html5/thumbnails/36.jpg)
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.