Learning database normalization, confused about 2NF

喜夏-厌秋 提交于 2019-12-22 16:29:14

问题


I was looking at this video on normalization on youtube and I have to say I am confused now, I there might be errors in the video even though it has 25 likes and only 1 dislike.

Normalization

Specifically regarding the 2NF section which can be found at the 5 minute mark.

The author says the 'Assignment Description' column depends on the Assignment ID column...yet there are there are different Assignment Descriptions for the same Assignment ID. He then 'normalizes' this table into 2NF by breaking it into two tables...one of them containing only Assignment ID and Assignment Description. And this table is not even in 1NF (non unique primary key) so how can it be 2NF?

Can someone tell me if this video is correct or incorrect regarding 2NF?


回答1:


From the relational point of view, that video is, at best, sloppy and careless. Some parts of it are simply wrong, including the part you cite. Don't watch any more videos from the "Database Normalization Master".

For a relation to be in 2NF it must

  • be in 1NF, and
  • have no partial key dependencies.

If an attribute depends on part of any candidate key, then there's a partial key dependency, and the relation is not in 2NF.

One point the video tries to make is that if the primary key is a single column, the relation is guaranteed to be in 2NF. But look at this table (from Wikipedia entry for 2NF).

Employees' Skills
--
Employee    Skill           Current Work Location
Jones       Typing          114 Main Street
Jones       Shorthand       114 Main Street
Jones       Whittling       114 Main Street
Bravo       Light Cleaning  73 Industrial Way
Ellis       Alchemy         73 Industrial Way
Ellis       Flying          73 Industrial Way
Harrison    Light Cleaning  73 Industrial Way

This relation has only one candidate key, {Employee, Skill}. But there's a partial key dependency between Employee and Current Work Location. Given any value for Employee, we find one and only one value for Current Work Location.

Changing the primary key to a surrogate ID number won't change the situation, although the video implies it will.

Employees' Skills
--
ID  Employee    Skill           Current Work Location
1   Jones       Typing          114 Main Street
2   Jones       Shorthand       114 Main Street
3   Jones       Whittling       114 Main Street
4   Bravo       Light Cleaning  73 Industrial Way
5   Ellis       Alchemy         73 Industrial Way
6   Ellis       Flying          73 Industrial Way
7   Harrison    Light Cleaning  73 Industrial Way

The primary key is a single column, which they say guarantees this relation is in 2NF. But it isn't. The video makers ignore the fact that most tables have multiple candidate keys, and that normalization takes every candidate key into account, not just the "special" candidate key called the primary key.

There are a lot of other problems with this video--so many that I didn't watch it all the way through. Life's too short to waste another minute on it.



来源:https://stackoverflow.com/questions/15166890/learning-database-normalization-confused-about-2nf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!