A3.2.6

Construct a database normalized to 3NF for a range of real-world scenarios

To normalize a database to 3NF : 1. Start with the unnormalized data 2. identify the primary key 3. remove repeating groups to reach 1NF 4. remove partial…

2 min read406 words
  • To normalize a database to 3NF:

    1. Start with the unnormalized data
    2. identify the primary key
    3. remove repeating groups to reach 1NF
    4. remove partial dependencies to reach 2NF
    5. remove transitive dependencies to reach 3NF
  • Real-world example:

Unnormalized table:

OrderIDCustomerNameCustomerPhoneProductIDProductNameQuantitySupplierName
1001Alice9999P1Keyboard2TechCo
1001Alice9999P2Mouse1TechCo
  • Problems:
    • repeated customer data
    • repeated product data
    • possible update anomalies
  • Step 1: 1NF
  • Ensure each field is atomic and each row stores one product per order.
  • The table shown is already close to 1NF because each cell contains one value only.

OrderLines

OrderIDCustomerNameCustomerPhoneProductIDProductNameQuantitySupplierName
1001Alice9999P1Keyboard2TechCo
1001Alice9999P2Mouse1TechCo
  • Candidate composite key:
    • (OrderID, ProductID)
  • Step 2: 2NF
  • Remove attributes that depend on only part of the composite key:
    • CustomerName, CustomerPhone depend on OrderID
    • ProductName, SupplierName depend on ProductID

Orders

OrderIDCustomerNameCustomerPhone
1001Alice9999

Products

ProductIDProductNameSupplierName
P1KeyboardTechCo
P2MouseTechCo

OrderItems

OrderIDProductIDQuantity
1001P12
1001P21
  • Step 3: 3NF
  • Remove transitive dependencies:
    • customer details should not be stored directly in Orders if they depend on CustomerID
    • if supplier details were expanded further, they might also need a separate Suppliers table

Customers

CustomerIDCustomerNameCustomerPhone
C1Alice9999

Orders

OrderIDCustomerID
1001C1

Products

ProductIDProductNameSupplierName
P1KeyboardTechCo
P2MouseTechCo

OrderItems

OrderIDProductIDQuantity
1001P12
1001P21
  • Why this is better:
    • customer data stored once
    • product data stored once
    • order-product relationship handled separately
    • easier updates and better integrity

How to write this in an exam

  1. State the original key or candidate key.
  2. Identify repeating groups or non-atomic values.
  3. Show the 1NF table.
  4. State which attributes have partial dependency and move them out to reach 2NF.
  5. State which attributes have transitive dependency and move them out to reach 3NF.
  6. List the final relations clearly with primary keys and foreign keys.

Final 3NF relations for the example

  • Customers(CustomerID, CustomerName, CustomerPhone)
  • Orders(OrderID, CustomerID)
  • Products(ProductID, ProductName, SupplierName)
  • OrderItems(OrderID, ProductID, Quantity)

Start typing to search all published objectives.