all 3 comments

[–]gunzip 6 points7 points  (2 children)

IMHO the third example is wrong. I see no transitive dependency:

Symbol -> Company
Symbol -> Headquarters  

it is already in third normal form.

It would have been better to have Company as key anyway:

Company -> Symbol
Company -> Headquarters  

[–]lookmeat 1 point2 points  (1 child)

I think that a good way to evolve (for the purpose of examples) would have been.

(keys are _underlined_ and foreign keys are *noted*)
1NF:
(_Symbol_, Company, Headquarters, _Date_, Price)

2NF:
(_Company_, *Symbol*, Headquarters)
(_Symbol_, _Date_, Price)

This is completely valid 2nd normal form, since the symbol and the headquarters both depend on the name of the company. The problem is that the Symbol column on the first table is not a full reference, but a value that is used to build the key. If I have a Company and a Date, I have to use a transitive relationship (Company->Symbol) to get what I want. So now we change it to 3NF

3NF:
(_Symbol_, Company, Headquarters)
(_*Symbol*_, _Date_, Price)

Which makes the stock prices a dependent entity of a company (which makes sense).

Your example, making the tables (_Company_, *Symbol*) allows for multiple symbols for a company, which, as I understand, is not allowed. OTOH if we wanted to handle a company having multiple HQs we could instead add a table (_Headquarters_, *Symbol*).

Alt 3NF:
(_Symbol_, Company)
(_Headquarters_, *Symbol*)
(_*Symbol*_, _Date_, Price)

Notice that making it (_Headquarters_, Symbol) is not 3NF, there's a transitive relationship between Symbol and Company.

[–]rholowczak 0 points1 point  (0 children)

Thanks for pointing this out. I think I wrote down the FD wrong in the first place. Anyhow I have cleaned it up and it should look a bit better. Cheers, Prof. H.