database design normalisation. last session looked at: –what databases were –where they are used...

23
Database Design Normalisation

Upload: peregrine-stokes

Post on 13-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

Database Design

Normalisation

Page 2: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

Last Session

• Looked at:– What databases were– Where they are used– How they are used

Page 3: 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

Page 4: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 5: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

Draw up a landscape table with 5 columns

0NF 1NF 2NF 3NF Table names

Page 6: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

List all the attributes from the paper record in the 0NF column

0NF 1NF 2NF 3NF Table names

Page 7: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 8: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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)

Page 9: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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)

Page 10: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 11: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 12: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 13: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 14: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 15: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 16: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 17: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 18: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 19: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 20: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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.

Page 21: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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

Page 22: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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.

Page 23: Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used

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)