Violation of 3NF if we use an auto-incremented identity column along with a PK

巧了我就是萌 提交于 2019-12-18 07:16:15

问题


As it is said in the book of Database Solutions Second Edition written by Thomas Connolly and Carolyn Begg page 180:

Third normal form (3NF)
A table that is already in 1NF and 2NF, and in which the values in all non-primary-key columns can be worked out from only the primary key column(s) and no other columns.

I have seen many scenarios where people use an identity column though they already have a primary key column in their table. A record can also be worked out from the identity column, so isn't it a violation of 3NF if we use an auto-incremented identity column along with a primary key in a table?

UPDATE: If it is not so which column should be referenced as a foreign key in another table.The primary key column or the Identity column?


回答1:


That book Database Solutions: A Step by Step Guide to Building Databases 2nd 2004 Edition is a mess. Unfortunately it says wrong things, it misleads, and a lot of their wording is extremely poor--like "work out"--which is informal & never defined.

Third normal form (3NF)
A table that is already in 1NF and 2NF, and in which the values in all non-primary-key columns can be worked out from only the primary key column(s) and no other columns.

That wrong definition is actually intended to be informal and for when a table has just one CK (candidate key). But the book doesn't say that except indirectly and later when it gives another wrong definition involving PKs (primary keys):

The formal definition for third normal form (3NF) is a table that is in first and second normal forms and in which no non-primary-key column is transitively dependent on the primary key.

Later still it says that there can be multiple CKs but it still gives a wrong definition:

Therefore, for tables with more than one candidate key you can use the generalized definition for 3NF, which is a table that is in 1NF and 2NF, and in which the values in all the non-primary-key columns can be worked out from only candidate key column(s) and no other columns.

It is wrongly saying "primary-key columns" where prime columns ie CK columns would be correct.

Their other book Database Systems 4th Edition 2005 also introduces special cases of definitions for when there is just one CK without saying so then later gives "general" definitions. At least those get "prime attribute" correct.

General definition for Third Normal Form (3NF) is a relation that is in First and Second Normal Form in which no non-candidate-key attribute is transitively dependent on any candidate key.

There is nothing unusual about a table having multiple CKs in any normal form.




回答2:


No. The 'official' wording of the definition of 3NF usually uses the term "prime attribute" or "non-prime attribute". If your book suggests that this means "attribute of the primary key" then throw your book in the bin. It is wrong. "prime attribute" means "attribute that is part of ANY of the keys" and "non-prime attribute" means "attribute that is not part of ANY of the keys". So introduction in the relation schema of your kind of "autoincrement attribute" (and of all of the applicable FDs that will make it a key) cannot possibly introduce a 3NF violation because it won't introduce a non-prime attribute.




回答3:


The paragraph you quoted is wrong - or at least it is so informal that it's useless as an explanation.

A relation R is in third normal form if it is in second normal form and every non-prime attribute of R is non-transitively dependent on each candidate key of R.

Codd E. F., “Further Normalization of the Data Base Relational Model”

Candidate keys are what matter. Nothing wrong with a table having more than one key.



来源:https://stackoverflow.com/questions/48754229/violation-of-3nf-if-we-use-an-auto-incremented-identity-column-along-with-a-pk

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