5. Examples of Normalization

Recap: What is Normalization?

  • First Normal Form (1NF):
    • Each cell must contain only only one value
    • Each row must be unique
  • Second Normal Form (2NF):
    • Data must depend on the entire primary key, and not just part of the primary key
  • Third Normal Form (3NF):
    • There can be no transitive dependencies
      • A column cannot depend on another column, unless that other column is a primary key
  • Example 1: Annual Tennis Tournament Winners

    • Original Table
      Annual Tournament Winners Table (Composite Key)
      tournament_nameyearwinnerwinner_dob
      St. John's Invitational2000Maxwell HouseJuly 21, 1990
      Toronto Open2010George AlbertsonMay 1, 1987
      St. John's Invitational2011Tiffany MastersonNovember 19, 1988
      Vancouver Memorial2003Steve MillerJanuary 30, 1980
    • Steps to Normalize
      • 1NF: Ensure Atomic Values
        • Step 1: Identify and Remove Non-Atomic Values
          • The table is in 1NF as each column contains atomic values. The primary key is a composite key of tournament_name and year.
      • 2NF: Remove Partial Dependencies
        • Step 2: Verify Partial Dependencies
          • The table is in 2NF as all non-key attributes are fully functionally dependent on the composite primary key (tournament_name and year).
      • 3NF: Remove Transitive Dependencies
        • Step 3: Remove Transitive Dependencies
          • The table is not in 3NF due to the transitive dependency between winner and winner_dob. To resolve this:
          • Normalization Steps
            • Create a separate table for winners:
            • Winners Table
              winner_idwinnerwinner_dob
              1Maxwell HouseJuly 21, 1990
              2George AlbertsonMay 1, 1987
              3Tiffany MastersonNovember 19, 1988
              4Steve MillerJanuary 30, 1980
            • Update the original table to use a foreign key:
            • Updated Annual Tournament Winners Table
              tournament_nameyearwinner
              St. John's Invitational2000Maxwell House
              Toronto Open2010George Albertson
              St. John's Invitational2011Tiffany Masterson
              Vancouver Memorial2003Steve Miller
  • Example 2: Student Courses

    • Original Table:
      Student Courses Table
      student_idstudent_namecourses
      1John DoeMath, Science, History
      2Jane SmithScience, English
      3Emily JohnsonMath, History
      4Michael BrownEnglish, History
    • Steps to Normalize
      • 1NF: Ensure Atomic Values
        • Step 1: Identify and Remove Non-Atomic Values
          • The table is not in 1NF because the courses column contains a list of values. Each course should be in its own row.
          • Normalized Table (1NF):
            Student Courses Table (1NF)
            student_idstudent_namecourse
            1John DoeMath
            1John DoeScience
            1John DoeHistory
            2Jane SmithScience
            2Jane SmithEnglish
            3Emily JohnsonMath
            3Emily JohnsonHistory
            4Michael BrownEnglish
            4Michael BrownHistory
      • 2NF: Remove Partial Dependencies
        • Step 2: Identify and Remove Partial Dependencies
          • The table is now in 1NF but not in 2NF. The student_name attribute is dependent only on student_id and not on the full composite key (student_id, course).
          • Normalization Steps
            • Create a separate table for students:
            • Students Table
              student_idstudent_name
              1John Doe
              2Jane Smith
              3Emily Johnson
              4Michael Brown
            • Update the courses table to use a foreign key:
            • Courses Table
              student_idcourse
              1Math
              1Science
              1History
              2Science
              2English
              3Math
              3History
              4English
              4History
      • 3NF: Remove Transitive Dependencies
        • Step 3: Remove Transitive Dependencies
          • There are no transitive dependencies in the students and courses tables, so we are already in 3NF.
  • Example 3: Customer Orders Table

    • Original Table:
      Orders Table
      Order_IDCustomer_NameCustomer_AddressOrder_DateProductProduct_Price
      1001John Smith123 Elm St2024-01-15Laptop$1200
      1002Jane Doe456 Oak St2024-01-17Smartphone$800
      1003Emily Johnson789 Pine St2024-01-20Tablet$600
      1004Michael Brown101 Maple St2024-01-22Monitor$200
    • 1NF: Ensure Atomic Values
      • Step 1: Identify and Remove Non-Atomic Values
        • The table is already in 1NF as each cell contains only atomic values.
    • 2NF: Remove Partial Dependencies
      • Step 2: Verify and Remove Partial Dependencies
        • The table is in 2NF because all non-key attributes are fully dependent on the primary key, Order_ID.
    • 3NF: Remove Transitive Dependencies
      • Step 3: Remove Transitive Dependencies
        • Product_Price depends on Product, not directly on Order_ID. As well, Customer_Address depends on Customer_Name. Thus, there are transitive dependencies.
        • Normalization Steps
          • Create a separate table for Customers:
          • Customers Table
            Customer_IDCustomer_NameCustomer_Address
            1001John Smith123 Elm St
            1002Jane Doe456 Oak St
            1003Emily Johnson789 Pine St
            1004Michael Brown101 Maple St
          • Create a separate table for Products:
          • Products Table
            Product_IDProductProduct_Price
            2001Laptop$1200
            2002Smartphone$800
            2003Tablet$600
            2004Monitor$200
          • Update the Orders table to use foreign keys:
          • Orders Table (3NF)
            Order_IDOrder_DateCustomer_IDProduct_ID
            10012024-01-1510012001
            10022024-01-1710022002
            10032024-01-2010032003
            10042024-01-2210042004
  • Example 4: Library Book Loans (Normalization)

    • Original Table (Not in 1NF):
      Library Book Loans Table
      Loan_IDBorrower_NameBooks_BorrowedLoan_Date
      2001Emily Clark"Introduction to Programming", "Data Structures"2024-02-01
      2002John Doe"Advanced Algorithms", "Computer Networks"2024-02-05
      2003Sophie Adams"Database Systems", "Operating Systems"2024-02-10
      2004Michael Lee"Web Development", "Software Engineering"2024-02-15
    • 1NF: Ensure Atomic Values
      • Step 1: Identify and Remove Non-Atomic Values
        • The table is not in 1NF because the Books_Borrowed column contains multiple values in a single cell.
        • Normalization Steps
          • Normalize to 1NF: Separate each book into its own row.
          • Library Book Loans Table (1NF)
            Loan_IDBorrower_NameBook_TitleLoan_Date
            2001Emily ClarkIntroduction to Programming2024-02-01
            2001Emily ClarkData Structures2024-02-01
            2002John DoeAdvanced Algorithms2024-02-05
            2002John DoeComputer Networks2024-02-05
            2003Sophie AdamsDatabase Systems2024-02-10
            2003Sophie AdamsOperating Systems2024-02-10
            2004Michael LeeWeb Development2024-02-15
            2004Michael LeeSoftware Engineering2024-02-15
    • 2NF: Remove Partial Dependencies
      • Step 2: Verify and Remove Partial Dependencies
        • The table is not in 2NF because the Borrower_Name is dependent only on part of the composite key (Loan_ID) and not on the entire composite key (Loan_ID, Book_Title).
        • Normalization Steps
          • Create a separate table for Borrowers:
          • Borrowers Table
            Loan_IDBorrower_Name
            2001Emily Clark
            2002John Doe
            2003Sophie Adams
            2004Michael Lee
          • Update the Loans table to use foreign keys:
          • Loans Table (2NF)
            Loan_IDBook_TitleLoan_Date
            2001Introduction to Programming2024-02-01
            2001Data Structures2024-02-01
            2002Advanced Algorithms2024-02-05
            2002Computer Networks2024-02-05
            2003Database Systems2024-02-10
            2003Operating Systems2024-02-10
            2004Web Development2024-02-15
            2004Software Engineering2024-02-15
    • 3NF: Remove Transitive Dependencies
      • Step 3: Remove Transitive Dependencies
        • There are no transitive dependencies in the borrowers or the loans tables, so we are already in 3NF.