⬅ Previous Topic
Database Normalization – 1NF, 2NF, 3NF, BCNFNext Topic ⮕
ER Diagrams and Schema Design⬅ Previous Topic
Database Normalization – 1NF, 2NF, 3NF, BCNFNext Topic ⮕
ER Diagrams and Schema DesignYou've learned about normalization — the art of splitting data to remove redundancy. But what if your queries now need to join five tables just to show a student's marks and teacher name? That's where denormalization comes in. It’s about breaking the rules — but for a reason: performance.
Denormalization is the process of combining data from multiple related tables into one to reduce joins and improve query speed. While it introduces redundancy, the trade-off can be worth it — especially for read-heavy systems.
-- Table: students
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(50),
class VARCHAR(10)
);
-- Table: results
CREATE TABLE results (
roll_no INT,
subject VARCHAR(30),
marks INT,
FOREIGN KEY (roll_no) REFERENCES students(roll_no)
);
-- Table: subjects
CREATE TABLE subjects (
subject VARCHAR(30) PRIMARY KEY,
teacher VARCHAR(50)
);
SELECT s.name, s.class, r.subject, r.marks, sub.teacher
FROM students s
JOIN results r ON s.roll_no = r.roll_no
JOIN subjects sub ON r.subject = sub.subject;
This query is correct and efficient for small data. But if millions of records grow and performance lags, consider denormalization.
CREATE TABLE student_report (
roll_no INT,
name VARCHAR(50),
class VARCHAR(10),
subject VARCHAR(30),
marks INT,
teacher VARCHAR(50)
);
SELECT name, class, subject, marks, teacher
FROM student_report
WHERE roll_no = 1;
name | class | subject | marks | teacher
----------------+--------+---------+--------+-----------
Aarav Sharma | 10A | Maths | 85 | Mr. Nair
Aarav Sharma | 10A | Science | 88 | Ms. Banerjee
Some systems use materialized views (precomputed queries stored as tables) to balance normalization with performance — often refreshed daily or hourly.
student_report
table for parent reportsDenormalization is not the opposite of good design — it’s a practical extension of it. When your database grows and performance becomes critical, denormalizing wisely can simplify your queries and boost speed. Just remember: with great performance comes great responsibility — keep your redundant data in check.
Coming up next: ER Diagrams – how to visually design and document your database schema for teams and stakeholders.
students
and attendance
tables. What does this imply?⬅ Previous Topic
Database Normalization – 1NF, 2NF, 3NF, BCNFNext Topic ⮕
ER Diagrams and Schema DesignYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.