Normalization of Tables: From 1NF to 2NF

Database normalization is the process of organizing data in a database to eliminate redundancy and improve data integrity. Normalization involves dividing a database into tables and establishing relationships between them based on their logical dependencies. The process of normalization is divided into several normal forms, each representing a higher level of data organization.

The first normal form (1NF) requires that each column in a table be atomic, meaning that it contains only a single value. This eliminates repeating groups of data and ensures that each piece of information is stored in only one place.

For example, suppose you have a table called "Students" that contains information about each student, including their name, address, phone number, and courses taken. The table might look like this:

Student IDNameAddressPhone NumberCourses Taken
1John Doe123 Main Street555-1234Math, Science
2Jane Smith456 Elm Street555-5678English, History

This table violates the 1NF because the "Courses Taken" column contains multiple values separated by commas. To convert this table to 1NF, you would split the "Courses Taken" column into a separate table called "Courses", which would contain a row for each course taken by each student:

Student IDNameAddressPhone Number
1John Doe123 Main Street555-1234
2Jane Smith456 Elm Street555-5678
Student IDCourse
1Math
1Science
2English
2History

Once the table has been normalized to 1NF, you can proceed to the second normal form (2NF), which requires that every non-key column in a table be fully dependent on the primary key. This means that if a table has a composite primary key (i.e., a primary key that consists of multiple columns), each non-key column must be dependent on the entire composite key, not just on a part of it.

For example, suppose you have a table called "Orders" that contains information about each customer order, including the order ID, customer ID, customer name, product ID, product name, and quantity ordered. The table might look like this:

Order IDCustomer IDCustomer NameProduct IDProduct NameQuantity
1100John Doe500Widget10
2100John Doe600Gadget5
3200Jane Smith500Widget2
4200Jane Smith700Gizmo3

This table violates the 2NF because the non-key columns "Customer Name" and "Product Name" depend only on the customer ID and product ID, respectively, not on the entire composite key. To convert this table to 2NF, you would split it into two tables: "Customers", which would contain information about each customer, and "Products", which would contain information about each product:

Customer IDCustomer Name
100John Doe
200Jane Smith

Did you find this article valuable?

Support Bit Fetch by becoming a sponsor. Any amount is appreciated!