notesonly.in

One notebook for every subject — open it anywhere.

Log in

Database Normalization: 1NF to BCNF With easy examples.

Normalization is the set of rules for organising tables so each fact is stored exactly once. The normal forms — 1NF, 2NF, 3NF, BCNF — are levels of discipline, each banning a specific kind of redundancy. A normalized database avoids update anomalies, where changing one fact in one place leaves a contradictory copy elsewhere.

It matters because unnormalized tables rot. Store a customer's address on every order row and one day two orders will disagree about where the customer lives — and no query can tell you which is right. Normalization trades a few extra joins for data you can trust.

Key Concepts

  • Functional dependency (FD): X → Y means "X determines Y" — rows agreeing on X must agree on Y. Example: StudentID → StudentName.
  • Key: columns determining every column in the table. The chosen minimal one is the primary key.
  • 1NF: every cell holds one atomic value — no lists, no repeating groups.
  • 2NF: in 1NF, plus every non-key column depends on the whole key, not part of it. StudentID → StudentName with key (StudentID, CourseID) violates 2NF.
  • 3NF: in 2NF, plus no transitive dependency — non-key columns must not depend on other non-key columns.
  • BCNF: stricter 3NF — every determinant (left side of every FD) must be a superkey.
  • Anomaly: an insert, update, or delete that corrupts data through redundancy.
  • Lossless decomposition: splitting tables so the original rebuilds perfectly via joins — required at every step.

How It Works

List the FDs, identify the key, and split off each violating dependency into its own table. The recipe: take the offending FD X → Y, create a new table (X, Y) with X as key, and leave X behind as a foreign key in the original. Repeat until every FD's left side is a key. Each step removes one class of redundancy while staying lossless.

Worked Example

Enroll(StudentID, StudentName, CourseID, CourseTitle, Grade). FDs: StudentID → StudentName; CourseID → CourseTitle; (StudentID, CourseID) → Grade.

  1. Key: neither StudentID nor CourseID alone determines all columns, but together they do — key = (StudentID, CourseID).
  2. 2NF: StudentName depends on only part of the key — partial dependency, violates 2NF. Split into Students(StudentID → StudentName) and Enroll1(StudentID, CourseID, CourseTitle, Grade).
  3. 3NF: in Enroll1, CourseTitle depends on CourseID, a non-key — transitive dependency. Split into Courses(CourseID → CourseTitle) and Enrollments(StudentID, CourseID → Grade).
  4. BCNF: every determinant is now a superkey in its table. Done.
  5. Payoff: 200 students × 5 courses each meant 1000 repeated name cells originally; now 200. Name changes need 1 update instead of 5, and 800 redundant copies are gone.

Common Misconceptions

  • "Higher normal form is always better." More joins can slow read-heavy reports. Data warehouses deliberately denormalize — normalize first, denormalize with reason.
  • "1NF means no duplicate rows." Duplicate rows are banned by keys. 1NF is about atomic values: one fact per cell.
  • "BCNF and 3NF are the same." BCNF is strictly stronger — the difference appears with overlapping candidate keys.

Real-World Applications

  • OLTP systems: banking and e-commerce databases sit at 3NF/BCNF so concurrent updates stay correct.
  • Data migration: cleaning a messy spreadsheet into 3NF is the standard first step to a real database.
  • Interviews: "normalize this table to 3NF" is one of the most asked database questions — the example above is the template.
  • ORM design: frameworks map normalized tables to clean object models.

Normalization is the discipline of storing each fact once: 1NF bans lists in cells, 2NF bans partial-key dependencies, 3NF bans transitive ones, BCNF closes the last loophole. Decompose on the violating FD and any messy table folds into trustworthy ones.