Second normal form

From Wikipedia, the free encyclopedia

Second normal form (2NF) is a normal form used in database normalization. It requires that all data elements in a table are functionally dependent on all of the table's primary key. If data elements only depend on part of a primary key, then they are parsed out to separate tables. If the table has a single field as the primary key, it is automatically in 2NF.

A table is in 2NF if and only if

  • It is in 1NF
  • Each non-primary key attribute is irreducibly dependent on the primary key

[edit] Example

Consider a table describing the source of machine parts, with the following attributes:

Parts source
Part's ID (primary key) Supplier's ID (primary key) Supplier's name Price Supplier's address
65 2 Stylized Parts 59.99 VA
73 2 Stylized Parts 20.00 VA
65 1 ACME Industries 69.99 CA

This table is in the first normal form, as all values in the table are atomic. The part's ID and the supplier's ID form the composite primary key because the same part can be supplied by multiple suppliers.

The relationship of the primary keys to price is correct: price is fully dependent on the primary key since different suppliers may charge a different price for the same part.

However, the supplier's name and address are only dependent on the supplier's ID, and thus this table breaks 2NF. Note the redundancy, where the name "Stylized Parts" and address "VA" is recorded twice. What if they relocate or merge with another company? This attribute should be placed in a second table like:

Suppliers
ID Name Address
1 ACME Industries CA
2 Stylized Parts VA

The original "Parts Source" table from above would then be modified thusly:

Parts source
Part's ID (primary key) Supplier's ID (primary key) Price
65 2 59.99
73 2 20.00
65 1 69.99

In order to find if a table is in 2NF, examine each non-key column of the table and ask whether or not it is fully dependent on every key in the composite key. If it isn't, it should be moved to its own table. Note that the next step, making sure that each non-key column is not dependent on any other non-key column, constitutes the third normal form.

[edit] Further reading

[edit] External links

Topics in Database normalization

First normal form | Second normal form | Third normal form
Boyce-Codd normal form | Fourth normal form | Fifth normal form | Domain/key normal form | Sixth normal form
Denormalization