Chapter 3 - Design Theory For Relational Databases
Chapter 3 - Design Theory For Relational 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
dependent on the
8
primary key,
Subject
RESULTS TABLE (key = StudentID+Subject)
A 2NF check
1
SUBJECTS TABLE (key = Subject)
1
8
2NF!
1
8
But is it 3NF?
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,
SUBJECTS TABLE (key = Subject)
non-key fields are
dependent on MORE 1
1
And 3NF says that
SUBJECTS TABLE (key = Subject)
non-key fields must
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)
StudentTable 1 GradesTable
¥
StudentID* StudentID* SubjectTable
Or…
¥ 1
StudentName Subject* Subject*
Address Grade SubjectCost
HouseName ¥
* primary key
1 HouseTable
HouseName*
HouseColour
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.