Marcus
Marcus

Reputation: 9439

Normalisation--2NF vs 3NF

We say 2NF is "the whole key" and 3NF "nothing but the key".

Referencing this answer by Smashery:
What are database normal forms and can you give examples?

The example used for 3NF is exactly the same as 2NF--it's a field which is dependent on only one key attribute. How is the example for 3NF different from the one for 2NF?

Upvotes: 35

Views: 41678

Answers (6)

Florin
Florin

Reputation: 1

First, we have to know the tools we work with:

candidate key attribute; non candidate key attribute; partial dependency; full dependency;

Candidate Key Attribute

A candidate key attribute is any column or combination of columns that can be/form primary key. You can have many candidate keys, but you will pick only one of these to be primary key. Still, any candidate key attribute is important in 2NF. No need to be primary key, or any key, it is enough to be a candidate key attribute. 2NF refers to CANDIDATE KEY. Those that say key or primary key instead of "candidate key" add to the confusion.

Non Candidate Key Attribute

Any column that can't be primary key and can't be part of the primary key.

Partial Dependency

Partial dependency arrives when there is a candidate key formed by MORE THAN ONE column, AND a non candidate key attribute depends only on A column that constitutes the candidate key.

Full Dependency

Any non candidate key attribute, if depends on a candidate key, then depends on the WHOLE candidate key. If the candidate key is formed by more than one column, then the dependent column must depend on any column that forms the candidate key.

Now you have the tools to understand 2NF and 3NF.

2NF does not allow partial dependency. If you find a non candidate key attribute that is partially dependent on a candidate key attribute, you must beak partial dependency to make it full dependency. So 2NF allows a non candidate key attribute to be full dependent on a candidate key attribute that is not primary key. It is just a possible primary key, if you pick it, but you are not forced to pick it. 2NF is compliant only by that.

Let's say you have it in 2NF. All non candidate key attributes are full dependent on candidate key attributes. But a non candidate key attribute is full dependent on a candidate key attribute that you did not pick it to be primary key. 3NF do not allow it. All full dependencies must be with primary key (at this point you picked a primary key already).

Upvotes: -1

nvogel
nvogel

Reputation: 25526

Suppose that some relation satisifies 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

You have spotted that the 3NF requirement is just a special case (but not really so special) of the 2NF requirement. 2NF in itself is not very important. The important issue is whether A is a superkey, not whether A just happens to be some part of a candidate key.

Upvotes: 14

rashedcs
rashedcs

Reputation: 3725

2NF follows the partial dependency whereas 3NF follows the transitive functional dependency. It is important to know that the 3NF must be in 2NF and support transitive functional dependency.

Upvotes: 0

Lordferrous
Lordferrous

Reputation: 716

2NF allows non-prime attributes to be functionally dependent on non-prime attributes

but

3NF allows non-prime attributes to be functionally dependent only on super key

Thus,when a table is in 3NF it is in 2NF and 3NF is stricter than 2NF

Hope this helps...

Upvotes: 11

tiktak
tiktak

Reputation: 1220

You have achieved the 3rd NF when there are no relations between the key and other columns that don't depend on it.

Not sure my professor would have said that like this but this is what it is.

If you're "in the field". Forget about the definitions. Look for "best practices". One is DRY : Don't Repeat Yourself.

If you follow that principle, you already master everything you need for NF.

Here is an example. Your table has the following schema:

PERSONS : id, name, age, car make, car model

Age and name are related to the person entry (=> id) but the model depends to the car and not the person.

Then, you would split it in two tables:

PERSONS : id, name, age, car_models_id (references CAR_MODELS.id)
CAR_MODELS : id, name, car_makes_id (references CAR_MAKES.id)
CAR_MAKES : id, name

You can have replication in 2FN but not in 3FN anymore.

Normalization is all about non-replication, consistency, and from another point of view foreign keys and JOINs.

The more normalized the better for data but not for performance nor understanding if it gets really too complicated.

Upvotes: 4

Unreason
Unreason

Reputation: 12704

Since you ask very specific question about an answer for existing so question here is an explanation of that (and basically I'll say what dportas already said in his answer, but in more words).

The examples of design that is not in 2NF and not in 3NF are not the same.

Yes, the dependency in both cases is on a single field.

However, in non 2NF example:

  • dependency is on the part of the primary key

while in non 3NF example (which is in 2NF):

  • dependency is on a field that is not a part of the primary key (and also notice that in that example it does satisfy 2NF; this is to show that even if you check for 2NF you should also check for 3NF)

In both cases to normalize you would create additional table which would not exhibit update anomalies (example of update anomaly: in 2NF example, what happens if you update Coursename for IT101|2009-2, but not for IT101|2009-1? You get inconsistent=meaningless=unusable data).

So, if you memorize the key, the whole key and nothing but the key, which covers both 2NF and 3NF, that should work for you in practice when normalizing. The distinction between 2NF and 3NF might seem subtle to you (question if in the additional dependency the attribute(s) on which the data is dependent are part of candidate key or not) - and, well, it is - so just accept it.

Upvotes: 11

Related Questions