Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Database Design Concepts Lecture 19 Term 2 week 8 Worked example of normalisation."— Presentation transcript:

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

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

3 Step by step plan to normalisation Investigate the users requirements Use documents ( there may be several)

4

5 Identify the attributes from the form List attributes Booking reference numberFlight number Customer nameDirection Customer AddressOperator PhoneArrival time Villa nameDeparture airport Addressnumber of passengers cost DestinationTotal Start date CostTotal Cost End Date

6 Give attributes a full name. Identify groups of data which repeat by adding brackets Add any missing attributes ( in this case weekly cost of villa) Booking reference number Customer Name Customer Address (Customer Phone) Villa name Villa Address Start Date End Date Cost of villa Weekly cost of villa A customer can have more than one phone number

7 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 (Direction Flight number Operator Arrival Time Departure airport Number of Passengers Cost of Flight Total cost of flight) Total cost of holiday

8 Find a key We 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 number If there is no key field you may need to add one. Name the table Booking Name any column that can have multiple values by creating a new attribute. In this case Customer phone number 2

9 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 attribute Named column Table name Unique identifier

10 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

11 First normal form Remove repeating groups Identify each repeating group. In this case the group with flight number For each group Remove the attributes of the repeating group from the existing table to a new table

12 ( Flight number, direction, operator, departure airport, flight time, arrival time, number of passengers,cost of flight, total cost for flight) Leaving 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 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)

13 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-

14 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

15 In this example Flight number appears a good idea It is a number ( key fields are often numbers- but not always) However Is it possible for more than one record in the table to have the same flight number? So it is not unique However could a booking have the same flight number more than once? So Booking reference number and flight number would be unique- A composite key

16 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

17 Second Normal Form All 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 week In other words is the value of the attribute associated with the value in the identifier or just one part of it

18 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

19 Direction is determined by the flight number only Work through the attributes individually in this way remembering which part of the key they are dependant on. Draw the functional determinancy diagram

20 Direction Operator Departure airport Flight Time Arrival Time Number of Passengers Cost of flight Total cost of flight Determined by flight number only

21 Booking reference no Flight no Total cost No of passengers Direction Operator Departure Airport Flight time Arrival time Cost of flight

22 Remove these attributes from the table Place 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-

23 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

24 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

25 Third normal form Remove 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

26 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 attributes Draw the functional determinancy table

27 Customer nameDestination Villa name ? Customer Address- customer name Start date of holiday Booking Reference Number Customer phone Customer name End date of holiday Booking reference number Customer phone 2 Customer name Weekly cost of villa- booking reference number Villa nameVilla cost of holiday Booking reference number Villa address Villa name Total cost of holiday Booking reference number

28 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.

29 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

30 ( 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 identifier Name the table, add customer number to the original booking table

31 ( 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 identifier Name the table, add villa number to the original booking table

32 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)

33 Check flights and booked flights- these have no transitive dependancies

34 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)

35 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)

36 Summary We have completed an example. You should be able to split tables to comply with the rules of 1 st, 2 nd and 3 rd 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.


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

Similar presentations


Ads by Google