database design normalisation. last session looked at: –what databases were –where they are used...
TRANSCRIPT
Database Design
Normalisation
Last Session
• Looked at:– What databases were– Where they are used– How they are used
Normalisation
• We have just done the top down Entity Relationship diagram method
• We now need to try the bottoms up approach called normalisation
Draw up a typical paper record for the project you are converting to a database
In this example we are using records of potential students enquiring about courses
Course Name
BTEC for IT Practitioners
Length 2 years
Tutor Len Shand
Location Main campus
Location code
001
Level 3
Date Name Address DOB Action
10/10/04 W Rooney Manchester 5/08/87 Send details
19/10/04 A Wenger London 5/3/47 Tutor to call
20/10/04 A Ferguson Manchester 28/4/42 Send details
Draw up a landscape table with 5 columns
0NF 1NF 2NF 3NF Table names
List all the attributes from the paper record in the 0NF column
0NF 1NF 2NF 3NF Table names
List all the attributes from the paper record in the 0NF column
0NF 1NF 2NF 3NF Table names
Course Name
Length
Tutor
Location
Location Code
Level
Date
Name
Address
DOB
Action
Identify the group or groups of attributes that are/or can be repeated on the paper record. Put a bracket around all of them
0NF 1NF 2NF 3NF Table names
Course Name
Length
Tutor
Location
Location Code
Level
(Date
Name
Address
DOB
Action)
Add a primary key for the repeating group and for the group only entered once.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
Copy the non-repeating group across into the 1NF column. This group is already in 1NF as it doesn’t have any brackets around it.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
1. Move the repeating group across into the 1NF column, making sure it is separated from the group already there. 2. Add the key from the non-repeating group to it and remove the brackets
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
This is now in first normal form
• There are no repeating groups• The second group has a compound primary key
(EnquirerID/CourseID)• This corresponds to 2 tables• All records can be recombined into one record by using the keys
• To put the database into 2NF we need to make sure it is in 1NF and all the non-key attributes depend entirely on the primary
key
Move groups which only have a simple primary key into the 2NF column
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
Next we identify those attributes in the other group that do not depend on both keys.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
Move the non-key attributes that depend on only one key across to the 2NF column. Then copy the attribute they do depend on into the
group with them.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
Name
Address
DOB
The remaining group (EnquirerID, CourseID, Date and Action are then moved into the 2NF column and given a unique ID. In our case
we call it the EnquiryID.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
Look at attributes that are not part of a key and work out if they depend on another attribute and not the primary key of the group they
are in.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
Move Location across into its own group and copy Location Code into it as a primary key. Then Location Code is also left as a foreign
key in the CourseID group.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
CourseID
Course Name
Length
Tutor
Location Code
Level
Location Code
Location
EnquirerID
Name
Address
DOB
EnquiryID
CourseID
EnquirerID
Date
Action
The final task is to give meaningful names to each group, which are now the tables to go into the database.
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Location Code
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
CourseID
Course Name
Length
Tutor
Location Code
Level
Location Code
Location
EnquirerID
Name
Address
DOB
EnquiryID
CourseID
EnquirerID
Date
Action
Course
Location
Enquirer
Enquiry
The End
• The database is now in third normal form• It is possible that the design arising from the two methods differs. • It is then up to the database designer to decide which solution to
implement.
Exercise
• Use the method above to normalise the following bank customer record– The account number is unique– The balance only depends on the account number
CustomerID 43543
Surname Jones
Postcode BA3 6TH
Phone number 654321
Account Number Account Type Description Balance
22442546 Gold Savings £10.00
44342322 Platinum Current £100.00
77164645 Silver Internet £500.00
Assignment scenarioYou have been asked to provide a solution to the problem of vehicle rentals at Joe’s Vehicle Rentals. The current
system consists of paper files for the vehicles and the people who are renting them.
The specifications for the project are:
• Manage rentals– Record new rentals– Record the returned vehicle– Update rentals if they are extended
• Keep vehicle details– Add new vehicles (by make, model and year)– Make vehicles inactive when they have reached 100000 miles– Keep vehicle attributes– Add new vehicle attributes (number of seats, engine size and fuel type)
• Include a table to hold the daily, weekly and monthly rental costs
• Keep customer details– Add new customers– Delete old customers (after 1 year and 1 day if no activity)– Update customer details
• Produce lists of vehicles on loan to a particular customer and when the vehicle is due back• Produce lists of vehicles still to be rented (available for rent)• Produce alphabetical list (by customer surname) of vehicles rented by customer• Produce a printed rental agreement for the customer to sign.
Assignment taskTASK 1 (P1, M1, D1)You have to write a section in the design documentation which discusses the choice of
software you will use for your implementation. This should be no more than 500 words and should be illustrated with diagrams.
You should:• Explain how a solution could be implemented using a spreadsheet
• Discuss the advantages and disadvantages of the spreadsheet for this particular problem
• Explain how a solution could be implemented using a database
• Discuss how the purpose and features of a relational database solution can overcome some of the problems inherent in the spreadsheet solution
• Make sure you include an explanation of the use of primary and foreign keys in your explanation
You do not need to discuss the choice of application (eg Access versus MySQL)