a normalisation example -...
TRANSCRIPT
![Page 1: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/1.jpg)
A Normalisation Example
![Page 2: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/2.jpg)
Take the following table.
StudentID is the primary key.
Is it 1NF?
![Page 3: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/3.jpg)
No. There are repeating groups (subject, subjectcost, grade)
How can you make it 1NF?
![Page 4: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/4.jpg)
Create new rows so each cell contains only one value
But now look – is the studentID primary key still valid?
![Page 5: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/5.jpg)
No – the studentID no longer uniquely identifies each row
You now need to declare studentID and subject together to uniquely identify each row.
So the new key is StudentID and Subject.
![Page 6: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/6.jpg)
So. We now have 1NF.
Is it 2NF?
![Page 7: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/7.jpg)
Studentname and address are dependent on studentID (which is part of the key)
This is good.
But they are not dependent on Subject (the other part of the
key)
![Page 8: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/8.jpg)
And 2NF requires…
All non-key fields are dependent on the ENTIRE key (studentID + subject)
![Page 9: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/9.jpg)
So it’s not 2NF
How can we fix it?
![Page 10: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/10.jpg)
Make new tables
• Make a new table for each primary key field
• Give each new table its own primary key
• Move columns from the original table to the new table that matches their primary key…
![Page 11: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/11.jpg)
Step 1
STUDENT TABLE (key = StudentID)
![Page 12: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/12.jpg)
Step 2
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
![Page 13: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/13.jpg)
Step 3
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
![Page 14: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/14.jpg)
Step 3
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
![Page 15: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/15.jpg)
Step 4 - relationships
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
![Page 16: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/16.jpg)
Step 4 - cardinality
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1 Each student can only appear ONCE in the student table
![Page 17: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/17.jpg)
Step 4 - cardinality
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
Each subject can only appear ONCE in the subjects table
![Page 18: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/18.jpg)
Step 4 - cardinality
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
A subject can be listed MANY times in the results table (for different students)
![Page 19: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/19.jpg)
Step 4 - cardinality
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
A student can be listed MANY times in the results table (for different subjects)
![Page 20: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/20.jpg)
A 2NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
SubjectCost is only dependent on the
primary key, Subject
![Page 21: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/21.jpg)
A 2NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
Grade is only dependent on the primary key
(studentID + subject)
![Page 22: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/22.jpg)
A 2NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
Name, Address are only dependent on the
primary key (StudentID)
![Page 23: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/23.jpg)
But is it 3NF?
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
So it is 2NF!
![Page 24: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/24.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
Oh oh… What?
![Page 25: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/25.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8 HouseName is
dependent on both StudentID + HouseColour
![Page 26: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/26.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
Or HouseColour is dependent on both
StudentID + HouseName
![Page 27: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/27.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
But either way, non-key fields are
dependent on MORE THAN THE PRIMARY
KEY (studentID)
![Page 28: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/28.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8 And 3NF says that
non-key fields must depend on nothing
but the key
![Page 29: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/29.jpg)
A 3NF check
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
WHAT DO WE DO?
![Page 30: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/30.jpg)
Again, carve off the offending fields
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
![Page 31: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/31.jpg)
A 3NF fix
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
![Page 32: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/32.jpg)
A 3NF fix
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
1
8
![Page 33: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/33.jpg)
A 3NF win!
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
1
8
8
1 8
Or…
![Page 34: A Normalisation Example - mohtarami.commohtarami.com/wp-content/uploads/2014/07/normalisation.pdf · A Normalisation Example . Take the following table. StudentID is the primary key](https://reader031.vdocument.in/reader031/viewer/2022020303/5b81dbe97f8b9a2b6f8d421f/html5/thumbnails/34.jpg)
The Reveal
Before…
After…
RESULTS TABLE (key = StudentID+Subject)
1 1
8
8
1
8
SUBJECTS TABLE (key = Subject)