Post

Dbs101_flippedclass5

Topic: Normal Forms


This flipped class we discussed about the five different types of normal form. Before starting with the normal forms, we have to know what normalization is. So normalization is a technique using which we can organize the data in the database to make sure that there is less repetition of data, that a large set of data is stored properly into a bunch of smaller tables, and that the tables have proper relationship between them.

We were divided into 4 different groups and the first group was given the task of presenting about the first and second normal forms(1NF and 2NF). As we were the first group we shared that:

  1. The first normal form(1NF)

    is basically the first step of the normalization process. 1NF is used to make the tables easier to extend and to retrieve data from it whenever required. There are 4 rules we need to follow to design the database:

  • Single valued attributes: each column should have a single value.
  • Attribute domain should not change:each values in the column should be of the same type.
    • For example if we have column storing the age of people it should not contain values such as names of people.
  • Unique name for Attributes: each column should have a unique name.
  • Order doesn’t matter: the order of the data stored in the table doesn’t matter.

Below is an example of how we can convert a non-1NF table into 1NF form

  • the table stores info about students and their courses but the column “courses” have multiple values which violates the 1NF rule

    Student IDNameCourses
    1JohnMath,Science
    2AliceEnglish, History
    3BobMath,English, Art
  • To convert the table into 1NF form we need to separate the multi-valued attribute to different rows.

    Student IDNameCourses
    1JohnMath
    1JohnScience
    2AliceEnglish,
    2AliceHistory
    3BobMath
    3BobEnglish
    3BobArt
  1. Second normal form(2NF)

    For a table to be in second normal form it needs to fulfill two conditions:

  • the table should be in first normal form.
  • there should not be any partial dependency.
    • partial dependency is a situation where an attribute depends on only a portion of the primary key rather than the whole primary key.

Below is an example of how we can remove a partial dependency:

Order_IDCustomer_IDProduct_IDOrder_DateCustomer_Name
11012012024-03-24John
21022022024-03-25Alice
31032012024-03-26Bob

“Customer_Name” depends only on “Customer_ID” and not on the entire primary key (“Order_ID”) which is a case of partial dependency and to remove it we need to make a new table for customers:

Customer_IDCustomer_Name
101John
102Alice
103Bob

Modified Table “Orders”: Order_ID|Customer_ID|Product_ID|Order_Date| ——–|———–|———-|———-| 1 | 101 |201 |2024-03-24| 2 |102 |202 |2024-03-25| 3 |103 |201 |2024-03-26|

The next presentation by group 2 was done on the topic Third Normal Form (3NF) and they shared that

  1. Third Normal Form (3NF)

    For a table to be in third normal form it needs to fulfill two conditions:

  • the table should be in second normal form.
  • there should not be any transitive dependency.
    • transitive dependency is where an attribute is functionally dependent on another attribute, which in turn is functionally dependent on the primary key.

Below is an example of how we can remove a transitive dependency: If we have a table where “Employee_ID” is the primary key and “Department_Name” depends on “Department_ID” and “Manager_Name” depends on “Manager_ID.” but “Manager_ID” itself depends on “Department_ID”. This creates a transitive dependency:

Original Table “Employee_Details”:

Employee_IDDepartment_IDDepartment_NameManager_IDManager_Name
1101Sales201John
2102Marketing202Alice
3101Sales203Bob

New Table “Department”:

Department_IDDepartment_Name
101Sales
102Marketing

New Table “Employee”:

Employee_IDDepartment_IDManager_ID
1101201
2102202
3101203

By doing this, we removed the transitive dependency because “Manager_Name” no longer indirectly depends on “Department_ID” through “Manager_ID.”.

The presentation by group 3 was on the topic Boyce-Codd Normal Form (BCNF) which was about:

  1. Boyce-Codd Normal Form (BCNF)

    It is an extension to the third normal form and can be also know as 3.5NF. For a table to be in BCNF it has to satisfy the following two conditions:

  • it should be in the Third Normal Form.
  • for a dependency A → B, A cannot be a non-prime attribute, if B is a prime attribute.
    • if a non-prime attribute determines a prime attribute, then the relation is not in BCNF. To bring the relation into BCNF, you would typically decompose it into smaller relations to eliminate this kind of dependency.

Below is an example of how we can make the table into a BCNF.

Employee_IDProject_IDEmployee_NameProject_NameDepartment
1101JohnProject XIT
1102JohnProject YIT
2101AliceProject XHR
3102BobProject YFinance

To bring the relation into BCNF, we decompose it into two relations:

  • Relation Employees with attributes Employee_ID, Employee_Name, Department
  • Relation Projects with attributes Project_ID, Project_Name

Updated relations:

Employees:

Employee_IDEmployee_NameDepartment
1JohnIT
2AliceHR
3BobFinance

Projects:

Project_IDProject_Name
101Project X
102Project Y

The last group that is group 4 were given the topic Fourth Normal Form.

  1. Fourth Normal Form(4NF)

    For any table satisfy the fourth normal form it should satisfy the following conditions:

    • It should be in the Boyce-Codd Normal Form.
    • the table should not have any Multi-valued Dependency.
      • a multi-valued dependency occurs when one attribute determines multiple values of another attribute, but a third attribute remains independent of these relationships and you need at least three columns in a table.

Below is an example of how 4NF is implemented: If we have a relation R(Student_ID, Subjects, Teacher) where:

  • Student_ID is the primary key
  • Subjects is a multi-valued attribute
  • Teacher is an attribute which not dependent on the subjects.
Student_IDSubjectsTeacher
1Math, SciMr. A
2Eng, HistMrs. B
3Math, EngMr. C

Now to make this into 4NF we need to seperate it into two relations:

Relation R1(Student_ID, Subjects):

Student_IDSubjects
1Math
1Sci
2Eng
2Hist
3Math
3Eng

Relation R2(Student_ID, Teacher):

Student_IDTeacher
1Mr. A
2Mrs. B
3Mr. C

Now, each relation is in Fourth Normal Form (4NF), as there are no multi-valued dependencies, and all attributes are fully functionally dependent on the primary key.

1
                                                THANK YOU
This post is licensed under CC BY 4.0 by the author.