2. First Normal Form (1NF)

What is First Normal Form?

  • A type of database normalization where a table has no groups/arrays of data

A database is in 1NF if:

  • Each column contains only a single value per row (i.e. no lists of values in a column)
  • Each column contains only one type of data
  • No two rows are identical
    • This means there is a unique identifer for each row, usually a primary key

Examples

Example of a table not in 1NF

Customer Orders

order_idcustomer_nameproducts
1AliceApples, Oranges
2BobBananas
3AliceApples, Bananas
  • Issue: The products column contains multiple values (lists of products).
  • How to Convert to 1NF:
    • Split the repeating group into individual rows.
    • Ensure each column contains only a single value for each record.

Table in 1NF

Customer Orders

order_idcustomer_nameproduct
1AliceApples
1AliceOranges
2BobBananas
3AliceApples
3AliceBananas
  • Fix: The products column is split, and each product is stored in its own row.

Benefits of 1NF

  • Avoids the issues of storing multiple values in a single field.
  • Simplifies querying the database (e.g., finding which customers ordered a specific product).
  • Ensures that each piece of data is atomic and easily manageable.