Uploaded by sayko here

Database normalization(2)

advertisement
Benha University
Faculty of Computers and AI
Database Normalization
Revision by Examples
Dr. Noha El-Attar
Bring the following relation to its 1NF
Primary key: Course Code
Bring the following table to its 3NF
studentID  primary key
Is it still valid?
No – the studentID no longer uniquely
identifies each row
Composite key
So the new key is StudentID and Subject.
We now have 1NF.
Is it 2NF?
Studentname and address are dependent on studentID
only
SubjectCost is dependent on Subject only
And 2NF requires…
All non-key fields are dependent on the
ENTIRE key (studentID + subject)
So it’s not 2NF
How can we fix it?
Step 1
STUDENT TABLE (key = StudentID)
Step 2
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
Step 3
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
Step 4 - relationships
STUDENT TABLE (key = StudentID)
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
Step 4 - cardinality
STUDENT TABLE (key = StudentID)
1
Each student can only appear
ONCE in the student table
8
8
A student can be listed
A subject
MANY can be listed MANY
times in the results table
times(for
in the results table (for
different subjects) different students)
RESULTS TABLE (key = StudentID+Subject)
SUBJECTS TABLE (key = Subject)
1
Each subject can only appear
ONCE in the subjects table
A 2NF check
STUDENT TABLE (key = StudentID)
8
Name, Address are only
dependent on the
primary key
(StudentID)
8
1
SUBJECTS TABLE (key = Subject)
1
SubjectCost is only
dependent on the
Grade is only dependent
primary key,
on the primary key
(studentID + subject)Subject
RESULTS TABLE (key = StudentID+Subject)
So it is 2NF!
STUDENT TABLE (key = StudentID)
1
8
8
But is it 3NF?
RESULTS TABLE (key = StudentID+Subject)
SUBJECTS TABLE (key = Subject)
1
A 3NF check
STUDENT TABLE (key = StudentID)
1
SUBJECTS TABLE (key = Subject)
8
8
1
RESULTS TABLE (key = StudentID+Subject)
8
Again, carve off the offending fields
1
1
8
8
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
1
The Reveal
Before…
After…
8
1
1
8
8
1
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key = StudentID+Subject)
Determine the NF
Client
It is in the 1NF
PropertyRentalOwner
PropertyNo  Paddress, rent, ownerNo, oName
ClientNo, PropertyNo  rentSart, rentFinish
Is it in the 2NF?
PropertyRentalOwner
It is in the 2NF
Is it in the 3NF?
It is now in the 3NF
Ref.
• Elmasri, R., Navathe, S., FUNDAMENTALS OF
Database Systems, SEVENTH EDITION, 2016.
• Robert Timmer-Arends
Download