2NF

Published 1 Year ago. data

2NF

[!example] A relation is in second normal form (2NF) if and only if:

  1. It is in 1NF.
  2. No non-prime attributes are functionally dependent on a subset of the candidate key(s). In other words, any column that’s not a key column is dependent on the whole information in the candidate key. ^[https://vertabelo.com/blog/normalization-1nf-2nf-3nf/]

2NF is a Data Normalisation form. It requires that all attributes must rely on the entire Candidate Key. In other words if an attribute relates to one key but not another this will not satisfy 2NF.

In this example we have a vending machine with drinks. Each drink has a price and an amount left. We could assume there would be ever more data in this table like the amount of coke in vending machine 2 and 3. This kind of structure may get confusing because only one of our two attributes relate to the entire Candidate Key.

Vending machineDrinkPricequantity
1Coke6.1010
2Pepsi6.2030
3Mount Dew5.8022
4Sprite1.2019
5Fanta3.3012

The price of the drinks here does not relate to the vending machine, only the drink. However the quantity of drinks in each vending machine relates to both, which drink, and which vending machine. To clear this up we can pull out the pricing data into a separate entity and create a relationship between the tables through the foreign key. In this case drink.

Vending MachineDrinkQuantity
1Coke10
2Pepsi30
3Mount Dew22
4Sprite19
5Fanta12
drinkprice
Coke6.10
Pepsi6.20
Mount Dew5.80
Sprite1.20
Fanta3.30

We now have two entities and all attributes relate to the entire candidate key. This therefor satisfies 2NF.

links to this note