Professional Documents
Culture Documents
Relational Databases
Functional Dependencies
Rules about FDs
Key & Super-Key
Normal forms
title
title year length
year length genre
genre studioName
studioName title
title year
year starName
starName
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox StarWars
Star Wars 1977
1977 CarrieFisher
Carrie Fisher
GoneWith
Gone WithTheTheWind
Wind 1939
1939 231drama
231 drama MGM
MGM StarWars
Star Wars 1977
1977 MarkHamill
Mark Hamill
Wayne'sWorld
Wayne's World 1992
1992 95comedy
95 comedy Paramount
Paramount StarWars
Wars 1977 HarrisonFord
Ford
Star 1977 Harrison
GoneWith
Gone WithThe
The1939
1939
Wind
Wind VivienLeigh
Vivien Leigh
Wayne'sWorld1992
Wayne's World1992 DanaCarvey
Dana Carvey
Wayne'sWorld1992
Wayne's World1992 MikeMeyers
Mike Meyers
Discuss
title
title year length
year length genre
genre studioName
studioName title
title year
year starName
starName
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox StarWars
Wars 1977 CarrieFisher
Fisher
Star 1977 Carrie
GoneWith
Gone WithTheTheWind
Wind 1939
1939 231drama
231 drama MGM
MGM StarWars
Wars 1977 MarkHamill
Hamill
Star 1977 Mark
Wayne'sWorld
Wayne's World 1992
1992 95comedy
95 comedy Paramount
Paramount StarWars
Wars 1977 HarrisonFord
Ford
Star 1977 Harrison
GoneWith
Gone WithThe
The1939
1939
Wind
Wind VivienLeigh
Vivien Leigh
Wayne'sWorld1992
Wayne's World1992 DanaCarvey
Dana Carvey
Wayne'sWorld1992
Wayne's World1992 MikeMeyers
Mike Meyers
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
¥ 1
* 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
title
title year length
year length genre
genre studioName
studioName starName
starName
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox CarrieFisher
Carrie Fisher
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox MarkHamill
Mark Hamill
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox HarrisonFord
Harrison Ford
GoneWith
Gone WithTheTheWind
Wind 1939
1939 231drama
231 drama MGM
MGM VivienLeigh
Vivien Leigh
Wayne'sWorld
Wayne's World 1992
1992 95comedy
95 comedy Paramount
Paramount DanaCarvey
Dana Carvey
Wayne'sWorld
Wayne's World 1992
1992 95comedy
95 comedy Paramount
Paramount MikeMeyers
Mike Meyers
title
title year length
year length genre
genre studioName
studioName
StarWars
Star Wars 1977
1977 124SciFi
124 SciFi Fox
Fox
GoneWith
Gone WithTheTheWind
Wind 1939
1939 231drama
231 drama MGM
MGM
Wayne'sWorld
Wayne's World 1992
1992 95comedy
95 comedy Paramount
Paramount
title
title year
year starName
starName
StarWars
Star Wars 1977
1977 CarrieFisher
Carrie Fisher
StarWars
Star Wars 1977
1977 MarkHamill
Mark Hamill
StarWars
Star Wars 1977
1977 HarrisonFord
Harrison Ford
GoneWith
Gone WithThe
The1939
1939
Wind
Wind VivienLeigh
Vivien Leigh
Wayne'sWorld1992
Wayne's World1992 DanaCarvey
Dana Carvey
Wayne'sWorld1992
Wayne's World1992 MikeMeyers
Mike Meyers
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.