问题
I\'ve viewed This post but I don\'t really understand the terms used (non-trivial function dependency, superkey)
From what I\'ve read 2nd normal form seems to relate to composite keys whereas 3rd normal form relates to primary keys.
I\'m not sure if this is correct though.
So 2nd normal form - there\'s a composite key and all fields in the table must relate to both of the composite key fields. If something doesn\'t relate then it should be refactored into another table.
3rd normal form - everything has to be dependent on the primary key - so I\'m guessing that in 3rd normal form there\'s only 1 key rather than in 2nd normal form where there can be composite keys?
Any advice appreciated.
回答1:
A proper subset or superset of a set is one that is not equal to it.
We say that a set of columns S functionally determines another set T in a table when each subrow for the first always appears with the same subrow for the second. We write S -> T and say S is the determinant set and T is the determined set. We call S -> T a FD (functional dependency). When S is a superset of T we say it is a trivial FD. When S is {A} we say A -> T & when T is {A} we say S -> A.
A superkey is a set of columns that uniquely identifies rows. That is so when it functionally determines every attribute. A CK (candidate key) is a superkey that contains no proper superkey. We can pick a CK as PK (primary key). A column is prime when it is in some CK.
That's enough to understand the answer that you link to:
The difference between 2NF and 3NF is this. Suppose that some relation satisfies a non-trivial functional dependency of the form A->B, where B is a nonprime attribute.
2NF is violated if A is not a superkey but is a proper subset of a candidate key
3NF is violated if A is not a superkey
The quote says a NF "is violated if" such an FD exists. Also it's only violated if such an FD exists.
A FD S -> T is partial when a proper subset of S also functionally determines T; otherwise it is full. Note that this does not involve CKs. A table is in 2NF when every non-prime column is fully functionally dependent on every CK.
S -> T is transitive when there is an X where S -> X and X -> T and not X -> S. Note that this does not involve CKs. A table is in 3NF when every non-prime column is non-transitively dependent on every CK.
(Note the alternate definitions of 2NF & 3NF different from the quote.)
来源:https://stackoverflow.com/questions/27474203/normal-forms-2nd-vs-3rd-is-the-difference-just-composite-keys-non-trivial-d