// DATABASE NORMALIZATION

Database Normalizationදත්ත සමුදාය සාමාන්‍යකරණය

The complete guide — anomalies, dependencies and 0NF → 3NF step by stepසම්පූර්ණ මාර්ගෝපදේශය — විෂමතා, යැපීම් සහ 0NF → 3NF පියවරෙන් පියවර

What is Normalization?

Normalization

Normalization is the process of organising the tables of a database properly. It reduces data redundancy and improves data integrity.

Unnormalized problems
Data redundancy
Insert anomalies
Update anomalies
Delete anomalies
Normalized results
Small, tidy tables
Data integrity
Proper dependencies
Faster performance
Normal form levels
0NF
Unnormalized
→
1NF
First
→
2NF
Second
→
3NF
Third
Our example data file

This unnormalized table is used to demonstrate every normal form

Student_IDNameAddressCourse_IDsSubjectsGradesTeacher_NameTeacher_Phone
S01KamalColomboC01, C02IT, MathA, BPerera, Silva071, 077
S02NimalGampahaC01ITBPerera071
S03SeethaKalutaraC02, C03Math, SciA, ASilva, Jayawardena077, 076
⚠ This table holds multi-valued cells — the problems of the 0NF form
සාමාන්‍යකරණය යනු?

Normalization

සාමාන්‍යකරණය යනු දත්ත සමුදායක වගු නිසිලෙස සකස් කිරීමේ ක්‍රියාවලියකි. මෙමගින් දත්ත අනුකෘතිය (Redundancy) අඩු කර, දත්ත ස්ථිරතාව (Integrity) වැඩිකරයි.

නොසාමාන්‍ය ගැටලු
දත්ත අනුකෘතිය
Insert විෂමතා
Update විෂමතා
Delete විෂමතා
සාමාන්‍ය ප්‍රතිඵල
කුඩා, පිළිවෙළ වගු
දත්ත ස්ථිරතාව
නිසිලෙස යැපීම්
ඉක්මන් ක්‍රියාකාරිත්වය
සාමාන්‍ය ස්වරූප මට්ටම්
0NF
නොසාමාන්‍ය
→
1NF
පළමු
→
2NF
දෙවන
→
3NF
තෙවන
අපේ උදාහරණ දත්ත ගොනුව

මෙම නොසාමාන්‍ය වගුව භාවිතා කර සියලු සාමාන්‍ය ස්වරූප පෙන්වනු ලැබේ

ශිෂ්‍ය_IDනමලිපිනයකේතයවිෂයශ්‍රේණියගුරු_නමගුරු_ දුරකතන
S01කමල්කොළඹC01, C02IT, MathA, Bපෙරේරා, සිල්වා071, 077
S02නිමල්ගම්පහC01ITBපෙරේරා071
S03සීතාකළුතරC02, C03Math, SciA, Aසිල්වා, ජයවර්ධන077, 076
⚠ මෙම වගුවේ බහු-අගයන් (Multi-valued) ඇත — 0NF ස්වරූපයේ ගැටලු
Anomalies

Types of data anomalies

Problems that appear when an unnormalized table is used

Insert Anomaly

When a new student is added who has not enrolled in any course yet, NULL values must be inserted.

Student_IDNameAddressCourse_IDSubjectGrade
S01KamalColomboC01ITA
S02NimalGampahaC01ITB
S04RangiMataraNULLNULLNULL
❌ Problem: Because Rangi has not enrolled in a course, the course columns stay NULL. If Student_ID and Course_ID form the composite primary key, the row cannot even be inserted with NULLs.
Update Anomaly

When teacher "Perera" changes his phone number, every row that mentions him must be updated.

Student_IDNameCourse_IDTeacher_NameTeacher_Phone
S01KamalC01Perera071 → 078 ✓
S01KamalC02Silva077
S02NimalC01Perera071 ✗ (forgotten!)
❌ Problem: The records of every student taking C01 with teacher "Perera" must be updated. If even one row is missed, data integrity is lost.
Delete Anomaly

Removing student S02 can also destroy the only remaining data about course C01.

Student_IDNameCourse_IDSubject_NameGrade
S01KamalC02MathB
S02NimalC01ITB
S03SeethaC03ScienceA
❌ Problem: When student S02 is deleted, all data about course C01 (IT) is destroyed with him. No other record mentions C01.
විෂමතා (Anomalies)

දත්ත විෂමතා වර්ග

නොසාමාන්‍ය වගුවක් භාවිතා කිරීමේදී ඇතිවන ගැටලු

Insert Anomaly — ඇතුළු කිරීමේ විෂමතාව

නව ශිෂ්‍යයෙකු ඇතුළු කිරීමේදී, ඔහු/ඇය කෝර්ස් ලියාපදිංචි නොවූ නම් NULL ඇතුළු කිරීමට සිදු වේ.

ශිෂ්‍ය_IDනමලිපිනයකෝර්ස්_IDවිෂයශ්‍රේණිය
S01කමල්කොළඹC01ITA
S02නිමල්ගම්පහC01ITB
S04රංගීමාතරNULLNULLNULL
❌ ගැටලුව: රංගී කෝර්ස් ලියාපදිංචි නොවූ නිසා, කෝර්ස් තීරු NULL ලෙස රැඳේ. ශිෂ්‍ය_ID සහ කෝර්ස්_ID ඒකාබද්ධ ප්‍රාථමික යතුර (Composite PK) නම් NULL ලෙස ඇතුළු කිරීම නොකළ හැකිය.
Update Anomaly — යාවත්කාලීන කිරීමේ විෂමතාව

ගුරු_නම "පෙරේරා" ඔහුගේ දුරකතන අංකය වෙනස් කිරීමේදී සියලු rows යාවත්කාලීන කිරීමට සිදුවේ.

ශිෂ්‍ය_IDනමකෝර්ස්_IDගුරු_නමගුරු_දුරකතන
S01කමල්C01පෙරේරා071 → 078 ✓
S01කමල්C02සිල්වා077
S02නිමල්C01පෙරේරා071 ✗ (අමතක!)
❌ ගැටලුව: "පෙරේරා" ගුරුවරයා C01 කෝර්ස් ගන්නා සියලු ශිෂ්‍යයන්ගේ records යාවත්කාලීන කිරීමට සිදුවේ. එකක් මඟ ගිය විට දත්ත ස්ථිරතාව නැති වේ.
Delete Anomaly — මකා දැමීමේ විෂමතාව

ශිෂ්‍ය S02 ඉවත් කිරීමෙදී, C01 කෝර්ස් පිළිබඳ ඇති එකම දත්ත ද නැතිවිය හැකිය.

ශිෂ්‍ය_IDනමකෝර්ස්_IDවිෂය_නමශ්‍රේණිය
S01කමල්C02MathB
S02නිමල්C01ITB
S03සීතාC03ScienceA
❌ ගැටලුව: S02 ශිෂ්‍යයා delete කළ විට, C01 (IT) කෝර්ස් පිළිබඳ ඇති සියලු දත්ත ද නාශ වේ. C01 කෝර්ස් ගැන තවත් කිසිදු record නොමැත.
Functional Dependencies

Types of dependencies

1. Full Dependency
Student_ID + Course_ID→Grade
The grade depends on both Student_ID and Course_ID together. Neither alone is enough.

➤ 2NF requires full dependencies — every non-key attribute must depend on the whole primary key.

2. Partial Dependency
Student_ID→Student_Name, Address
Course_ID→Subject_Name
Student_Name and Address depend on only part of the primary key (Student_ID).

➤ Converting properly to 2NF removes partial dependencies.

3. Transitive Dependency
Student_ID→Teacher_ID
Teacher_ID→Teacher_Name, Teacher_Phone
∴ Student_ID → Teacher_Name (transitive)
Teacher_Name does not depend directly on the primary key (Student_ID); it depends on it through Teacher_ID.

➤ Converting properly to 3NF removes transitive dependencies.

Summary visualization
Dependency typeShapeProblemSolution
FullWhole PK → AttrNone2NF-ready
PartialPart of PK → AttrRedundancyApply 2NF
TransitivePK → X → AttrUpdate anomalyApply 3NF
ක්‍රියාකාරී යැපීම් (Functional Dependencies)

යැපීම් වර්ග

1. සම්පූර්ණ යැපීම (Full Dependency)
ශිෂ්‍ය_ID + කෝර්ස්_ID→ශ්‍රේණිය
ශ්‍රේණිය, ශිෂ්‍ය_ID හා කෝර්ස්_ID දෙකම මත රඳා පවතී. එකක් ඇතිව නොලැබේ.

➤ 2NF සඳහා සම්පූර්ණ යැපීම් අවශ්‍යය — සියලු non-key attributes, සම්පූර්ණ primary key මත රැඳිය යුතුය.

2. අර්ධ යැපීම (Partial Dependency)
ශිෂ්‍ය_ID→ශිෂ්‍ය_නම, ලිපිනය
කෝර්ස්_ID→විෂය_නම
ශිෂ්‍ය_නම සහ ලිපිනය, primary key කොටසක් (ශිෂ්‍ය_ID) පමණක් මත රඳා පවතී.

➤ 2NF නිසිලෙස කිරීමෙන් අර්ධ යැපීම් ඉවත් කෙරේ.

3. සංක්‍රාන්ති යැපීම (Transitive Dependency)
ශිෂ්‍ය_ID→ගුරු_ID
ගුරු_ID→ගුරු_නම, ගුරු_දුරකතන
∴ ශිෂ්‍ය_ID → ගුරු_නම (සංක්‍රාන්ති)
ගුරු_නම, primary key (ශිෂ්‍ය_ID) මත සෘජුව රඳා නොපවතී, නමුත් ගුරු_ID හරහා රඳා පවතී.

➤ 3NF නිසිලෙස කිරීමෙන් සංක්‍රාන්ති යැපීම් ඉවත් කෙරේ.

සාරාංශ දෘශ්‍යකරණය
යැපීම් වර්ගයස්වරූපයගැටලුවවිසඳුම
සම්පූර්ණPK සම්පූර්ණය → Attrනැත2NF සාදා ඇත
අර්ධPK කොටස → AttrRedundancy2NF කරන්න
සංක්‍රාන්තිPK → X → AttrUpdate anomaly3NF කරන්න
0NF

Zero Normal Form

Unnormalized Form (UNF)

Characteristics: multi-valued cells and repeating groups

  • ✗  A single cell holds several values
  • ✗  Repeating groups exist
Student_IDNameAddressCourse_IDsSubject_NamesGrades
S01KamalColomboC01, C02IT, MathA, B
S02NimalGampahaC01ITB
S03SeethaKalutaraC02, C03Math, ScienceA, A
❌ A cell contains several values, like "C01, C02" — the 0NF problem
↓
1NF

First Normal Form

Atomicity + Unique rows
  • Every cell holds an atomic (single) value
  • No repeating groups
  • A primary key is defined
  • No duplicate column names
⚠ Problem columns: Course_IDs Subject_Names Grades
✅ Solution: split the values into separate rows
Student_ID 🔑Course_ID 🔑NameAddressSubject_NameGradeTeacher_NameT_Phone
S01C01KamalColomboITAPerera071
S01C02KamalColomboMathBSilva077
S02C01NimalGampahaITBPerera071
S03C02SeethaKalutaraMathASilva077
S03C03SeethaKalutaraScienceAJayawardena076
✅ 1NF — Composite PK = (Student_ID + Course_ID) | ❌ Problems: Name, Address (partial dependency) | Teacher_Name, T_Phone (transitive)
↓
2NF

Second Normal Form

1NF + No Partial Dependencies
  • Satisfies 1NF
  • No partial dependencies
  • Non-key attributes depend on the whole PK
✅ Solution: move the partially-dependent columns into separate tables
Student table
Student_ID 🔑NameAddress
S01KamalColombo
S02NimalGampaha
S03SeethaKalutara
Course table
Course_ID 🔑Subject_Name
C01IT
C02Math
C03Science
Enrolment table
Student_ID 🔑Course_ID 🔑GradeTeacher_NameT_Phone
S01C01APerera071
S01C02BSilva077
S02C01BPerera071
S03C02ASilva077
S03C03AJayawardena076
✅ 2NF — Name and Address moved out | ❌ Problem: Teacher_Name → T_Phone (a transitive dependency remains)
↓
3NF

Third Normal Form

2NF + No Transitive Dependencies
  • Satisfies 2NF
  • No transitive dependencies
  • No non-key attribute depends on another non-key attribute
✅ Solution: move Teacher_Name and T_Phone into a Teacher table
Enrolment table (3NF)
Student_ID 🔑Course_ID 🔑GradeTeacher_ID
S01C01AT01
S01C02BT02
S02C01BT01
S03C02AT02
S03C03AT03
Teacher table
Teacher_ID 🔑Teacher_NamePhone
T01Perera071
T02Silva077
T03Jayawardena076
Student table
Student_ID 🔑NameAddress
S01KamalColombo
S02NimalGampaha
S03SeethaKalutara
Course table
Course_ID 🔑Subject_Name
C01IT
C02Math
C03Science
✅ 3NF complete! All transitive dependencies removed. Teacher_Name no longer depends on a non-key column. No more update anomalies.
Summary
FormCriterionRemoves
1NFAtomic values, no repeating groupsMulti-valued cells
2NF1NF + full dependencyPartial dependencies
3NF2NF + no transitiveTransitive dependencies
0NF

Zero Normal Form — ශුන්‍ය සාමාන්‍ය ස්වරූපය

Unnormalized Form (UNF)

ලක්ෂණ: බහු-අගයන් (Multi-valued), නැවත නැවත කණ්ඩායම් (Repeating Groups)

  • ✗  Cell එකකට අගු කිහිපයක් ඇත
  • ✗  Repeating group ඇත
ශිෂ්‍ය_IDනමලිපිනයකෝර්ස්_IDsවිෂය_නම්ශ්‍රේණි
S01කමල්කොළඹC01, C02IT, MathA, B
S02නිමල්ගම්පහC01ITB
S03සීතාකළුතරC02, C03Math, ScienceA, A
❌ Cell එකක "C01, C02" ලෙස values කිහිපයක් ඇත — 0NF ගැටලු
↓
1NF

First Normal Form — පළමු සාමාන්‍ය ස්වරූපය

Atomicity + Unique rows
  • සෑම cell එකක්ම atomic (ඒකීය) අගයක් ඇත
  • Repeating groups නැත
  • Primary Key නිර්වචිතයි
  • Column names නැවත නොහැකිය
⚠ ගැටලු ඇති columns: කෝර්ස්_IDs විෂය_නම් ශ්‍රේණි
✅ විසඳුම: කිහිපු rows ලෙස වෙන් කරන්න
ශිෂ්‍ය_ID 🔑කෝර්ස්_ID 🔑නමලිපිනයවිෂය_නමශ්‍රේණියගුරු_නමගුරු_දු.
S01C01කමල්කොළඹITAපෙරේරා071
S01C02කමල්කොළඹMathBසිල්වා077
S02C01නිමල්ගම්පහITBපෙරේරා071
S03C02සීතාකළුතරMathAසිල්වා077
S03C03සීතාකළුතරScienceAජයවර්ධන076
✅ 1NF — Composite PK = (ශිෂ්‍ය_ID + කෝර්ස්_ID) | ❌ ගැටලු: නම, ලිපිනය (අර්ධ යැපීම) | ගුරු_නම, ගුරු_දු. (සංක්‍රාන්ති)
↓
2NF

Second Normal Form — දෙවන සාමාන්‍ය ස්වරූපය

1NF + No Partial Dependencies
  • 1NF සපුරාලේ
  • අර්ධ යැපීම් (Partial Dependencies) නැත
  • Non-key attributes, සම්පූර්ණ PK මත රැඳේ
✅ විසඳුම: අර්ධ යැපීම් ඇති columns වෙනම වගු ලෙස ඉවත් කරන්න
ශිෂ්‍ය වගුව
ශිෂ්‍ය_ID 🔑නමලිපිනය
S01කමල්කොළඹ
S02නිමල්ගම්පහ
S03සීතාකළුතර
කෝර්ස් වගුව
කෝර්ස්_ID 🔑විෂය_නම
C01IT
C02Math
C03Science
ලියාපදිංචි වගුව
ශිෂ්‍ය_ID 🔑කෝර්ස්_ID 🔑ශ්‍රේණියගුරු_නමගුරු_දු.
S01C01Aපෙරේරා071
S01C02Bසිල්වා077
S02C01Bපෙරේරා071
S03C02Aසිල්වා077
S03C03Aජයවර්ධන076
✅ 2NF — නම, ලිපිනය වෙනම ගියා | ❌ ගැටලු: ගුරු_නම → ගුරු_දු. (සංක්‍රාන්ති යැපීම ඉතිරි ය)
↓
3NF

Third Normal Form — තෙවන සාමාන්‍ය ස්වරූපය

2NF + No Transitive Dependencies
  • 2NF සපුරාලේ
  • සංක්‍රාන්ති යැපීම් (Transitive Dependencies) නැත
  • Non-key attribute, Non-key attribute මත රඳා නොපවතී
✅ විසඳුම: ගුරු_නම, ගුරු_දු. ගුරු වගුවකට ගෙනයන්න
ලියාපදිංචි වගුව (3NF)
ශිෂ්‍ය_ID 🔑කෝර්ස්_ID 🔑ශ්‍රේණියගුරු_ID
S01C01AT01
S01C02BT02
S02C01BT01
S03C02AT02
S03C03AT03
ගුරු වගුව
ගුරු_ID 🔑ගුරු_නමදුරකතන
T01පෙරේරා071
T02සිල්වා077
T03ජයවර්ධන076
ශිෂ්‍ය වගුව
ශිෂ්‍ය_ID 🔑නමලිපිනය
S01කමල්කොළඹ
S02නිමල්ගම්පහ
S03සීතාකළුතර
කෝර්ස් වගුව
කෝර්ස්_ID 🔑විෂය_නම
C01IT
C02Math
C03Science
✅ 3NF සම්පූර්ණයි! සියලු සංක්‍රාන්ති යැපීම් ඉවත් විය. ගුරු_නම, ගුරු_ID (PK නොවන column) මත රඳා නොපවතී. Update anomaly නැත.
සාරාංශය — Summary
ස්වරූපයනිර්ණායකයඉවත් කරන්නේ
1NFAtomic values, No repeating groupsMulti-valued cells
2NF1NF + Full dependencyPartial dependencies
3NF2NF + No transitiveTransitive dependencies