Database normalization is one of the most important concepts in DBMS. It helps in reducing redundancy and improving data integrity.
In this post, letβs understand 1NF, 2NF, and 3NF using a simple real-world example β and implement everything using Oracle Live SQL.
π§©The Base Table
Weβll start with this unnormalized table:
StudentID StudentName CourseID CourseName Instructor InstructorPhone
S01 Arjun C101 DBMS Dr. Kumar 9876543210
S01 Arjun C102 Data Mining Dr. Mehta 9123456780
S02 Priya C101 DBMS Dr. Kumar 9876543210
S03 Kiran C103 AI Dr. Rao 9988776655
β οΈ Step 1 β Identify Anomalies
In the base table, we can observe three major problems:
πΈ Insertion Anomaly
You cannot insert a new course unless a student enrolls in it.
πΈ Update Anomaly
If Dr. Kumar changes his phone number, we must update it in multiple rows.
πΈ Deletion Anomaly
If all students drop the βAIβ course, we lose Dr. Raoβs details completely.
So, letβs fix these issues one normalization step at a time.
π§± Step 2 β Convert to 1NF (First Normal Form)
Rule:
Each cell must contain only atomic (single) values β no repeating groups.
β Our base table already satisfies 1NF, but weβll create it formally in SQL.
CREATE TABLE BaseTable (
StudentID VARCHAR2(10),
StudentName VARCHAR2(50),
CourseID VARCHAR2(10),
CourseName VARCHAR2(50),
Instructor VARCHAR2(50),
InstructorPhone VARCHAR2(15)
);
π§© Step 3 β Convert to 2NF (Second Normal Form)
Rule:
Remove partial dependencies β no non-key attribute should depend on part of a composite key.
Here, the composite key is (StudentID, CourseID).
We separate the data into three smaller tables:
- Student
- Course
- Enrollment
CREATE TABLE Student (
StudentID VARCHAR2(10) PRIMARY KEY,
StudentName VARCHAR2(50)
);
CREATE TABLE Course (
CourseID VARCHAR2(10) PRIMARY KEY,
CourseName VARCHAR2(50),
Instructor VARCHAR2(50),
InstructorPhone VARCHAR2(15)
);
CREATE TABLE Enrollment (
StudentID VARCHAR2(10),
CourseID VARCHAR2(10),
PRIMARY KEY (StudentID, CourseID),
FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
FOREIGN KEY (CourseID) REFERENCES Course(CourseID)
);
Now, data redundancy is reduced β but we can still do better!
π§ Step 4 β Convert to 3NF (Third Normal Form)
Rule:
Remove transitive dependencies β non-key attributes should not depend on other non-key attributes.
Here, InstructorPhone depends on Instructor, not on CourseID.
So, weβll create a separate Instructor table and link it to Course via an InstructorID.
CREATE TABLE Instructor (
InstructorID VARCHAR2(10) PRIMARY KEY,
InstructorName VARCHAR2(50),
InstructorPhone VARCHAR2(15)
);
CREATE TABLE Course (
CourseID VARCHAR2(10) PRIMARY KEY,
CourseName VARCHAR2(50),
InstructorID VARCHAR2(10),
FOREIGN KEY (InstructorID) REFERENCES Instructor(InstructorID)
);
π§Ύ Step 5 β Final 3NF Schema Diagram
Tables:
- Student(StudentID, StudentName)
- Instructor(InstructorID, InstructorName, InstructorPhone)
- Course(CourseID, CourseName, InstructorID)
- Enrollment(EnrollID, StudentID, CourseID) This structure removes redundancy completely and makes the database consistent and scalable.
π§© Step 6 β Sample Data Insertion
INSERT INTO Student VALUES ('S01', 'Arjun');
INSERT INTO Student VALUES ('S02', 'Priya');
INSERT INTO Student VALUES ('S03', 'Kiran');
INSERT INTO Instructor VALUES ('I01', 'Dr. Kumar', '9876543210');
INSERT INTO Instructor VALUES ('I02', 'Dr. Mehta', '9123456780');
INSERT INTO Instructor VALUES ('I03', 'Dr. Rao', '9988776655');
INSERT INTO Course VALUES ('C101', 'DBMS', 'I01');
INSERT INTO Course VALUES ('C102', 'Data Mining', 'I02');
INSERT INTO Course VALUES ('C103', 'AI', 'I03');
INSERT INTO Enrollment (StudentID, CourseID) VALUES ('S01', 'C101');
INSERT INTO Enrollment (StudentID, CourseID) VALUES ('S01', 'C102');
INSERT INTO Enrollment (StudentID, CourseID) VALUES ('S02', 'C101');
INSERT INTO Enrollment (StudentID, CourseID) VALUES ('S03', 'C103');
π Step 7 β Display Data using JOINs
Now, we can easily query all students, their courses, and their instructors:
SELECT
s.StudentID,
s.StudentName,
c.CourseName,
i.InstructorName,
i.InstructorPhone
FROM Enrollment e
JOIN Student s ON e.StudentID = s.StudentID
JOIN Course c ON e.CourseID = c.CourseID
JOIN Instructor i ON c.InstructorID = i.InstructorID;
Output:
StudentID StudentName CourseName InstructorName InstructorPhone
S01 Arjun DBMS Dr. Kumar 9876543210
S01 Arjun Data Mining Dr. Mehta 9123456780
S02 Priya DBMS Dr. Kumar 9876543210
S03 Kiran AI Dr. Rao 9988776655
β Final Thoughts
Through normalization:
- Data redundancy is minimized
- Update, insertion, and deletion anomalies are eliminated
- The database becomes more reliable and scalable
By implementing these steps in Oracle Live SQL, you can clearly visualize how normalization improves your database structure.
A special thanks to @santhoshnc sir for mentoring me on these Normalisation topics!
Top comments (0)