Unit 18 Database Design Extended Diploma in...
Transcript of Unit 18 Database Design Extended Diploma in...
![Page 1: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/1.jpg)
Unit 18 Database Design
Extended Diploma in ICT
![Page 2: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/2.jpg)
The ERD is a top down method of modelling the real life business
Normalisation is a bottom up method Often based on existing system (possibly paper)
Both methods can be used
They may give different results and the designer has to decide which ones to implement
![Page 3: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/3.jpg)
Make sure the database is:
As intended
Always unambiguous
Make sure the table
Has a field that uniquely identifies each row (the primary key)
Does not contain duplicate fields
Does not repeat the same type of values
Does not contain fields that belong in other tables
![Page 4: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/4.jpg)
Make sure fields
Represent a characteristic of the table subject
Contain a single value
Are atomic (not multipart)
Are not calculated
Are unique throughout the database
Have an appropriate name
![Page 5: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/5.jpg)
The basic levels:
0NF- list of attributes without calculated fields and removal of duplicated data
1NF – the removal of repeating groups
2NF – free from partial-key dependencies
3NF – non-key dependencies removed
Some of the higher levels are named after their originator (e.g. the Boyce-Codd Normal Form (4th stage but not called 4NF!))
![Page 6: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/6.jpg)
Examine the existing documentation
Reports
Screen layouts
![Page 7: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/7.jpg)
UNF - an unnormalised table
1.List all the attributes – a column for each data item
2.Ignore any calculated fields
1. Fields that can be derived from data in other fields
3.Enter sample data into the fields
4.Identify a key
5.Remove duplicate data
![Page 8: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/8.jpg)
Contains repeating attributes
![Page 9: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/9.jpg)
1NF = First Normal Form
Move any repeating attributes to a new table
(Any data field which has more than one entry for a single value of the key).
Identify repeating fields
Place in a new table with a copy of the key from the UNF
Use the original key as part of a new key in the new table (a compound key – which must be unique)
![Page 10: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/10.jpg)
![Page 11: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/11.jpg)
Remove partial key dependencies
Any simple key dependencies go straight to 2NF
Any key which only depends on part of the key for its value
Given A is there only one possible value for B (& vice versa)?
Eg employee name, department number and department name only depend on employee number
Put into a new table
Let A become the primary key
Keep in original table as foreign key
![Page 12: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/12.jpg)
![Page 13: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/13.jpg)
Tables with zero or only one non-key attribute go straight to 3NF
Move to a new table any attributes which are more dependent on another attribute than the key
Move a copy of the attribute that they are dependent on (becomes 1° key)
Remains as foreign key in original table
![Page 14: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/14.jpg)
![Page 15: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/15.jpg)
1NF – no repeating columns
2NF – in 1NF and columns only depend on the whole primary key
3NF – 2NF and all non-key columns depend only on the primary key
Transitive dependency – a non-key column is dependent on another non-key column; remove the columns dependant on non-key items to another table
![Page 16: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/16.jpg)
1. List all the attributes you need to store
2. Remove all calculated fields (eg age,total)
3. Make sure each attribute is atomic
4. Remove any repeating items to a separate table and make a link (using keys) to establish the relation
5. The structure will now be in first normal form
![Page 17: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/17.jpg)
We want a database to record enquiries to the college
![Page 18: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/18.jpg)
We want a database to record enquiries to the college Course
Length
Location
Level
Date
Name
Address
DOB
Age
Action to take
![Page 19: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/19.jpg)
Course
Duration
Tutor
Location
Level
Date Name Address DOB Action
![Page 20: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/20.jpg)
Course ICT
Duration 2
Tutor Bob Higgie
Location Folly Lane
Level 3
Date Name Address DOB Action
07/05/2011 Theo Walcott The Emirates 16/03/1989 Send prospectus
08/06/2011 Brian Cox Manchester 03/03/1968 Ring back
21/07/2011 Kate Winslett Hollywood 05/10/1975 None
![Page 21: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/21.jpg)
Address field is not atomic
We should fix this into address 1 etc, but for simplicity in the examples I am going to leave it.
![Page 22: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/22.jpg)
0NF 1NF 2NF 3NF Table names
![Page 23: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/23.jpg)
0NF 1NF 2NF 3NF Table names
![Page 24: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/24.jpg)
0NF 1NF 2NF 3NF Table names
Course Name
Length
Tutor
Location
Level
Date
Name
Address
DOB
Action
![Page 25: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/25.jpg)
0NF 1NF 2NF 3NF Table names
Course Name
Length
Tutor
Location
Level
(Date
Name
Address
DOB
Action)
![Page 26: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/26.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
![Page 27: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/27.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
![Page 28: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/28.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
![Page 29: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/29.jpg)
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 attributes (excluding the keys) depend entirely on the primary
key
![Page 30: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/30.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
![Page 31: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/31.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
![Page 32: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/32.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
Name
Address
DOB
![Page 33: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/33.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
![Page 34: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/34.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
![Page 35: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/35.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
CourseID
Course Name
Length
TutorID
Location
Level
TutorID
Tutor
EnquirerID
Name
Address
DOB
EnquiryID
CourseID
EnquirerID
Date
Action
![Page 36: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/36.jpg)
0NF 1NF 2NF 3NF Table names
CourseID
Course Name
Length
Tutor
Location
Level
(EnquirerID
Date
Name
Address
DOB
Action)
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
CourseID
Date
Name
Address
DOB
Action
CourseID
Course Name
Length
Tutor
Location
Level
EnquirerID
Name
Address
DOB
EnquiryID
EnquirerID
CourseID
Date
Action
CourseID
Course Name
Length
TutorID
Location
Level
TutorID
Tutor
EnquirerID
Name
Address
DOB
EnquiryID
CourseID
EnquirerID
Date
Action
Course
Tutor
Enquirer
Enquiry
![Page 37: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/37.jpg)
Put the table name in capital letters
Underline the primary key
List the attributes after the primary key
Put an * next to the foreign keys
COURSE (CourseID, CourseName, Length, TutorID*, Location, Level)
TUTOR (TutorID, Tutor)
ENQUIRER (EnquirerID, Name, Address, DOB)
ENQUIRY (EnquiryID, CourseID*, EnquirerID*, Date, Action)
![Page 38: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/38.jpg)
1NF – no repeating columns
2NF – in 1NF and columns only depend on the whole primary key
3NF – 2NF and all non-key columns depend only on the primary key
Transitive dependency – a non-key column is dependent on another non-key column; remove the columns dependant on non-key items to another table
![Page 39: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/39.jpg)
1. List all the attributes you need to store
2. Remove all calculated fields (eg age,total)
3. Make sure each attribute is atomic
4. Remove any repeating items to a separate table and make a link (using keys) to establish the relation
5. The structure will now be in first normal form
![Page 40: Unit 18 Database Design Extended Diploma in ICTwiki.computing.hct.ac.uk/_media/computing/btec/... · Extended Diploma in ICT ... UNF - an unnormalised table 1. List all the attributes](https://reader035.fdocuments.us/reader035/viewer/2022063017/5fd7560d1375067f896e2497/html5/thumbnails/40.jpg)
Normalise the data required for our veterinary surgery.
Use the Veterinary Surgery Paper record on the wiki