What is 1NF truly?

…衆ロ難τιáo~ 提交于 2020-01-15 07:04:04

问题


While studying relational databases, I ran into this confusing page where the following snapshot summarizes my confusion:

Why does the author say that Subject Table is in 1NF when student_id 401 and subject Math is repeated in the same way the blue depicts? This seems like a contradiction.


回答1:


The key concept this page fails to mention is that the data contained in the row must not be duplicated, meaning that a single key value cannot have multiple values for a single column. The real problem is that for student id of 401, the first table specifies the name twice.

The text following the last table should read "In Subject table concatenation of subject_id and student_id is the primary key". The reason the new subject table is okay is because the key is actually both of these values, so while 401 is repeated, the key is 10, 401 and 11, 401, which are two distinct values. Likewise, math is repeated, but it is the data for two separate keys; it isn't repeated within a row. Because these key values are different, it is okay.

The page you referenced doesn't give a very precise definition. I hope this explanation helps. Keep checking other sites to get a more clear understanding. Wikipedia has a good example and a precise definition, though it is a bit abstract and hard to follow. http://en.wikipedia.org/wiki/First_normal_form




回答2:


Chris Date gives a correct and concise definition of 1NF in his book An Introduction to Database Systems, 7th ed, p 357.

A relvar is in 1NF if and only if, in every legal value of that relvar, every tuple contains exactly one value for each attribute.

"One value" appearing in more than one tuple (more than one row) doesn't violate 1NF. In the "Student table", each tuple (each row) contains exactly one value for each attribute. As far as we can tell from the sample data, it's in 1NF.

In the relational model, that "one value" can be arbitrarily complex--audio recordings, video, engineering drawings, etc. (Ibid, p 114)



来源:https://stackoverflow.com/questions/16927257/what-is-1nf-truly

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