Design Theory For Relational Databases - Readmore
Design Theory For Relational Databases - Readmore
Databases
Functional Dependencies
Rules about FDs
Key & Super-Key
Normal forms
Is it 1NF?
No. There are repeating groups (subject, subjectcost, grade)
Is it 2NF?
2NF
A relation R is in second normal form (2NF) if and only
if it is in 1NF and every non-key attribute is fully
dependent on the primary key
But they are not dependent on Subject (the other part of the key)
And 2NF requires…
1
SUBJECTS TABLE (key = Subject)
1
SUBJECTS TABLE (key = Subject)
1
A subject can be listed MANY
times in the results table (for
different students)
8
1
SUBJECTS TABLE (key = Subject)
1
A student can be listed MANY
times in the results table (for
different subjects)
8
1
SUBJECTS TABLE (key = Subject)
SubjectCost is only
8
dependent on the
8
primary key,
Subject
RESULTS TABLE (key = StudentID+Subject)
A 2NF check
1
SUBJECTS TABLE (key = Subject)
1
8
1
So it is SUBJECTS TABLE (key = Subject)
2NF! 1
8
But is it
8
Oh oh… 1
SUBJECTS TABLE (key = Subject)
What?
8
1
HouseName is
SUBJECTS TABLE (key = Subject)
dependent on both
1
StudentID +
HouseColour
8
1
Or HouseColour is
SUBJECTS TABLE (key = Subject)
dependent on both
1
StudentID +
HouseName
8
1
But either way,
non-key fields are SUBJECTS TABLE (key = Subject)
dependent on MORE 1
1
And 3NF says that
non-key fields must SUBJECTS TABLE (key = Subject)
depend on nothing 1
1
WHAT DO SUBJECTS TABLE (key = Subject)
WE DO? 1
8
8
1
1
8
1
1
8
1
SUBJECTS TABLE (key = Subject)
RESULTS TABLE (key =
StudentID+Subject)
Or…
The Reveal
Before…
After… 1
8
1
1
8
TABLE SUB-TABLE
TABLE ??
SUB-TABLE
BCNF is the same, but the embedded table may involve key attributes.
BCNF
3NF Boyce-Codd
a nontrivial functional a nontrivial functional dependency
dependency: X => A holds X => A holds in R, then:
in R, either a) X is a superkey of R
(a) X is a superkey of R, or
(b) (b) A is a prime attribute of
R.