- Part Zero: Schemas that are not relational
- Part One: Schemas that are not 1st normal form
- Part Two: Schemas that are not 2nd normal form
- Part Three: Schemas that are not 3rd normal form
Today, I describe 3rd Normal Form and give a ridiculous example of a table that breaks the rule badly. I’ve seen 3NF defined this way:
“A relation (table) R, in second normal form is in third normal form if every non-prime attribute of R is non-transitively dependent on every candidate key of R.”
That’s Wikipedia’s definition of third normal form. And they do a decent job explaining what that means. They reference E. F. Codd’s paper Further Normalization of the Data Base Relational Model 1972. But I couldn’t find a reference online and I was too busy this week to dig out my alumni card and visit the Davis Centre Library.
The House That Jack Built
Before we get into the ridiculous example, I want to talk a bit about the English nursery rhyme The House That Jack Built.
It’s a cumulative poem that starts with the line This is the house that jack built. It repeats and expands (like the songs I Know an Old Lady Who Swallowed a Fly or The Twelve Days of Christmas)
By the end of the poem we have a beautiful run-on sentence where the subject of the poem has very very little to do with the house that Jack built. Here is the rhyme:
This is the house that Jack built.
This is the malt that lay in the house that Jack built.
This is the rat that ate the malt
that lay in the house that Jack built.… and so on until …
This is the farmer sowing his corn
That kept the cock that crowed in the morn
That waked the priest all shaven and shorn
That married the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog that worried the cat
That killed the rat that ate the malt
That lay in the house that Jack built.
But the thing that makes this nursery rhyme interesting is the same thing that makes tables violate third normal form. If we think of each database row as a sentence and the subject as the primary key. This brings us to our ridiculous example.
The Ridiculous Example
Houses (hope you like scroll bars)
Builder |
|
|
|
|
|
|
|
|
|
|
Jack |
Malt |
Rat |
Cat |
Dog |
Cow (crumpled horn) |
Maiden (all forlorn) |
Man (tattered and torn) |
Priest (shaven and shorn) |
Cock (crowed in the morn) |
Farmer (sowing corn) |
This table is nowhere near third normal form; it’s in a different time zone! This table is supposed to be about houses, not livestock and 16th century English people. So when you’re designing your tables remember: No run on sentences!
The Other Normal Forms
So that’s the series. I could continue with 4NF, 5NF and BCNF (and others!) but I won’t for a few reasons.
- Most people who pay attention to 1NF, 2NF and 3NF almost always design databases in the other normal forms without trying.
- The other normal forms are dull enough that it becomes a challenge to actually come up with a counter example that can seriously be called ridiculous
- I’ve never heard of any problems encountered by anyone caused by not paying attention to the other normal forms. If you know of any, let me know!
Liked This Series?
Hey you, yeah you. The web surfer. Thanks for coming by. I’m glad you’re visiting this post. That’s what I wrote it for. If you liked this series, you may also like my series on Transaction Levels. Or maybe have a look at some of my favorite posts (or some of yours).
Now clicking the links, that’s the first step. Subscribing to my RSS feed – That’s a whole other thing. So here’s the the deal, if you put my blog into your RSS reader, I promise to write stuff worth belonging in it. Go on, subscribe.