Normalizing Database (2NF)

Normalizing a database to the Second Normal Form (2NF) involves removing partial dependencies and ensuring that all non-key attributes are fully functionally dependent on the entire primary key. To achieve 2NF, you must first ensure that your database is in 1NF and then address partial dependencies. Let’s go through the process of normalizing a sample database to 2NF with an example:

Example: Student Course Registration Database

Consider a database that tracks student course registrations, where each student can register for multiple courses, and each course can have multiple students. We’ll start with an unnormalized table and then proceed to normalize it to 2NF.

Unnormalized Table (1NF):

StudentIDCourseIDCourseNameInstructor
1101MathProf. Smith
1102PhysicsProf. Johnson
2101MathProf. Smith
3103ChemistryProf. Davis

In this table, (StudentID, CourseID) is the composite primary key.

Step 1: Identify Partial Dependencies

A partial dependency exists when a non-key attribute depends on only a part of the primary key. In our example, the Instructor column depends only on the CourseID, not the entire composite primary key.

Step 2: Create Separate Tables

We will create two separate tables: one for students and one for courses.

Students Table:

StudentIDStudentName
1John
2Jane
3Alex

Courses Table:

CourseIDCourseName
101Math
102Physics
103Chemistry

Step 3: Address Partial Dependencies

Now we need to address the partial dependency of the Instructor column. To do this, we create a new table for course instructors.

Instructors Table:

CourseIDInstructor
101Prof. Smith
102Prof. Johnson
103Prof. Davis

Step 4: Update Original Table

We can now remove the CourseName and Instructor columns from the original table since this information is now stored in separate tables.

StudentRegistrations Table (2NF):

StudentIDCourseID
1101
1102
2101
3103

In this normalized structure, the StudentRegistrations table only contains the primary key attributes (StudentID, CourseID).

Conclusion:
The database is now in Second Normal Form (2NF). We’ve removed partial dependencies by separating the data into related tables, ensuring that non-key attributes depend on the entire primary key.

Remember, normalization doesn’t stop at 2NF. Depending on the complexity of your data and the specific requirements, you might need to further normalize the database to higher normal forms, such as 3NF or BCNF, to eliminate other types of anomalies and redundancies.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *