Database Normalizationදත්ත සමුදාය සාමාන්යකරණය
The complete guide — anomalies, dependencies and 0NF → 3NF step by stepසම්පූර්ණ මාර්ගෝපදේශය — විෂමතා, යැපීම් සහ 0NF → 3NF පියවරෙන් පියවර
Normalization
Normalization is the process of organising the tables of a database properly. It reduces data redundancy and improves data integrity.
Insert anomalies
Update anomalies
Delete anomalies
Data integrity
Proper dependencies
Faster performance
This unnormalized table is used to demonstrate every normal form
| Student_ID | Name | Address | Course_IDs | Subjects | Grades | Teacher_Name | Teacher_Phone |
|---|---|---|---|---|---|---|---|
| S01 | Kamal | Colombo | C01, C02 | IT, Math | A, B | Perera, Silva | 071, 077 |
| S02 | Nimal | Gampaha | C01 | IT | B | Perera | 071 |
| S03 | Seetha | Kalutara | C02, C03 | Math, Sci | A, A | Silva, Jayawardena | 077, 076 |
Normalization
සාමාන්යකරණය යනු දත්ත සමුදායක වගු නිසිලෙස සකස් කිරීමේ ක්රියාවලියකි. මෙමගින් දත්ත අනුකෘතිය (Redundancy) අඩු කර, දත්ත ස්ථිරතාව (Integrity) වැඩිකරයි.
Insert විෂමතා
Update විෂමතා
Delete විෂමතා
දත්ත ස්ථිරතාව
නිසිලෙස යැපීම්
ඉක්මන් ක්රියාකාරිත්වය
මෙම නොසාමාන්ය වගුව භාවිතා කර සියලු සාමාන්ය ස්වරූප පෙන්වනු ලැබේ
| ශිෂ්ය_ID | නම | ලිපිනය | කේතය | විෂය | ශ්රේණිය | ගුරු_නම | ගුරු_ දුරකතන |
|---|---|---|---|---|---|---|---|
| S01 | කමල් | කොළඹ | C01, C02 | IT, Math | A, B | පෙරේරා, සිල්වා | 071, 077 |
| S02 | නිමල් | ගම්පහ | C01 | IT | B | පෙරේරා | 071 |
| S03 | සීතා | කළුතර | C02, C03 | Math, Sci | A, A | සිල්වා, ජයවර්ධන | 077, 076 |
Types of data anomalies
Problems that appear when an unnormalized table is used
When a new student is added who has not enrolled in any course yet, NULL values must be inserted.
| Student_ID | Name | Address | Course_ID | Subject | Grade |
|---|---|---|---|---|---|
| S01 | Kamal | Colombo | C01 | IT | A |
| S02 | Nimal | Gampaha | C01 | IT | B |
| S04 | Rangi | Matara | NULL | NULL | NULL |
When teacher "Perera" changes his phone number, every row that mentions him must be updated.
| Student_ID | Name | Course_ID | Teacher_Name | Teacher_Phone |
|---|---|---|---|---|
| S01 | Kamal | C01 | Perera | 071 → 078 ✓ |
| S01 | Kamal | C02 | Silva | 077 |
| S02 | Nimal | C01 | Perera | 071 ✗ (forgotten!) |
Removing student S02 can also destroy the only remaining data about course C01.
| Student_ID | Name | Course_ID | Subject_Name | Grade |
|---|---|---|---|---|
| S01 | Kamal | C02 | Math | B |
| S02 | Nimal | C01 | IT | B |
| S03 | Seetha | C03 | Science | A |
දත්ත විෂමතා වර්ග
නොසාමාන්ය වගුවක් භාවිතා කිරීමේදී ඇතිවන ගැටලු
නව ශිෂ්යයෙකු ඇතුළු කිරීමේදී, ඔහු/ඇය කෝර්ස් ලියාපදිංචි නොවූ නම් NULL ඇතුළු කිරීමට සිදු වේ.
| ශිෂ්ය_ID | නම | ලිපිනය | කෝර්ස්_ID | විෂය | ශ්රේණිය |
|---|---|---|---|---|---|
| S01 | කමල් | කොළඹ | C01 | IT | A |
| S02 | නිමල් | ගම්පහ | C01 | IT | B |
| S04 | රංගී | මාතර | NULL | NULL | NULL |
ගුරු_නම "පෙරේරා" ඔහුගේ දුරකතන අංකය වෙනස් කිරීමේදී සියලු rows යාවත්කාලීන කිරීමට සිදුවේ.
| ශිෂ්ය_ID | නම | කෝර්ස්_ID | ගුරු_නම | ගුරු_දුරකතන |
|---|---|---|---|---|
| S01 | කමල් | C01 | පෙරේරා | 071 → 078 ✓ |
| S01 | කමල් | C02 | සිල්වා | 077 |
| S02 | නිමල් | C01 | පෙරේරා | 071 ✗ (අමතක!) |
ශිෂ්ය S02 ඉවත් කිරීමෙදී, C01 කෝර්ස් පිළිබඳ ඇති එකම දත්ත ද නැතිවිය හැකිය.
| ශිෂ්ය_ID | නම | කෝර්ස්_ID | විෂය_නම | ශ්රේණිය |
|---|---|---|---|---|
| S01 | කමල් | C02 | Math | B |
| S02 | නිමල් | C01 | IT | B |
| S03 | සීතා | C03 | Science | A |
Types of dependencies
➤ 2NF requires full dependencies — every non-key attribute must depend on the whole primary key.
➤ Converting properly to 2NF removes partial dependencies.
➤ Converting properly to 3NF removes transitive dependencies.
| Dependency type | Shape | Problem | Solution |
|---|---|---|---|
| Full | Whole PK → Attr | None | 2NF-ready |
| Partial | Part of PK → Attr | Redundancy | Apply 2NF |
| Transitive | PK → X → Attr | Update anomaly | Apply 3NF |
යැපීම් වර්ග
➤ 2NF සඳහා සම්පූර්ණ යැපීම් අවශ්යය — සියලු non-key attributes, සම්පූර්ණ primary key මත රැඳිය යුතුය.
➤ 2NF නිසිලෙස කිරීමෙන් අර්ධ යැපීම් ඉවත් කෙරේ.
➤ 3NF නිසිලෙස කිරීමෙන් සංක්රාන්ති යැපීම් ඉවත් කෙරේ.
| යැපීම් වර්ගය | ස්වරූපය | ගැටලුව | විසඳුම |
|---|---|---|---|
| සම්පූර්ණ | PK සම්පූර්ණය → Attr | නැත | 2NF සාදා ඇත |
| අර්ධ | PK කොටස → Attr | Redundancy | 2NF කරන්න |
| සංක්රාන්ති | PK → X → Attr | Update anomaly | 3NF කරන්න |
Zero Normal Form
Characteristics: multi-valued cells and repeating groups
- ✗ A single cell holds several values
- ✗ Repeating groups exist
| Student_ID | Name | Address | Course_IDs | Subject_Names | Grades |
|---|---|---|---|---|---|
| S01 | Kamal | Colombo | C01, C02 | IT, Math | A, B |
| S02 | Nimal | Gampaha | C01 | IT | B |
| S03 | Seetha | Kalutara | C02, C03 | Math, Science | A, A |
First Normal Form
- Every cell holds an atomic (single) value
- No repeating groups
- A primary key is defined
- No duplicate column names
| Student_ID 🔑 | Course_ID 🔑 | Name | Address | Subject_Name | Grade | Teacher_Name | T_Phone |
|---|---|---|---|---|---|---|---|
| S01 | C01 | Kamal | Colombo | IT | A | Perera | 071 |
| S01 | C02 | Kamal | Colombo | Math | B | Silva | 077 |
| S02 | C01 | Nimal | Gampaha | IT | B | Perera | 071 |
| S03 | C02 | Seetha | Kalutara | Math | A | Silva | 077 |
| S03 | C03 | Seetha | Kalutara | Science | A | Jayawardena | 076 |
Second Normal Form
- Satisfies 1NF
- No partial dependencies
- Non-key attributes depend on the whole PK
| Student_ID 🔑 | Name | Address |
|---|---|---|
| S01 | Kamal | Colombo |
| S02 | Nimal | Gampaha |
| S03 | Seetha | Kalutara |
| Course_ID 🔑 | Subject_Name |
|---|---|
| C01 | IT |
| C02 | Math |
| C03 | Science |
| Student_ID 🔑 | Course_ID 🔑 | Grade | Teacher_Name | T_Phone |
|---|---|---|---|---|
| S01 | C01 | A | Perera | 071 |
| S01 | C02 | B | Silva | 077 |
| S02 | C01 | B | Perera | 071 |
| S03 | C02 | A | Silva | 077 |
| S03 | C03 | A | Jayawardena | 076 |
Third Normal Form
- Satisfies 2NF
- No transitive dependencies
- No non-key attribute depends on another non-key attribute
| Student_ID 🔑 | Course_ID 🔑 | Grade | Teacher_ID |
|---|---|---|---|
| S01 | C01 | A | T01 |
| S01 | C02 | B | T02 |
| S02 | C01 | B | T01 |
| S03 | C02 | A | T02 |
| S03 | C03 | A | T03 |
| Teacher_ID 🔑 | Teacher_Name | Phone |
|---|---|---|
| T01 | Perera | 071 |
| T02 | Silva | 077 |
| T03 | Jayawardena | 076 |
| Student_ID 🔑 | Name | Address |
|---|---|---|
| S01 | Kamal | Colombo |
| S02 | Nimal | Gampaha |
| S03 | Seetha | Kalutara |
| Course_ID 🔑 | Subject_Name |
|---|---|
| C01 | IT |
| C02 | Math |
| C03 | Science |
| Form | Criterion | Removes |
|---|---|---|
| 1NF | Atomic values, no repeating groups | Multi-valued cells |
| 2NF | 1NF + full dependency | Partial dependencies |
| 3NF | 2NF + no transitive | Transitive dependencies |
Zero Normal Form — ශුන්ය සාමාන්ය ස්වරූපය
ලක්ෂණ: බහු-අගයන් (Multi-valued), නැවත නැවත කණ්ඩායම් (Repeating Groups)
- ✗ Cell එකකට අගු කිහිපයක් ඇත
- ✗ Repeating group ඇත
| ශිෂ්ය_ID | නම | ලිපිනය | කෝර්ස්_IDs | විෂය_නම් | ශ්රේණි |
|---|---|---|---|---|---|
| S01 | කමල් | කොළඹ | C01, C02 | IT, Math | A, B |
| S02 | නිමල් | ගම්පහ | C01 | IT | B |
| S03 | සීතා | කළුතර | C02, C03 | Math, Science | A, A |
First Normal Form — පළමු සාමාන්ය ස්වරූපය
- සෑම cell එකක්ම atomic (ඒකීය) අගයක් ඇත
- Repeating groups නැත
- Primary Key නිර්වචිතයි
- Column names නැවත නොහැකිය
| ශිෂ්ය_ID 🔑 | කෝර්ස්_ID 🔑 | නම | ලිපිනය | විෂය_නම | ශ්රේණිය | ගුරු_නම | ගුරු_දු. |
|---|---|---|---|---|---|---|---|
| S01 | C01 | කමල් | කොළඹ | IT | A | පෙරේරා | 071 |
| S01 | C02 | කමල් | කොළඹ | Math | B | සිල්වා | 077 |
| S02 | C01 | නිමල් | ගම්පහ | IT | B | පෙරේරා | 071 |
| S03 | C02 | සීතා | කළුතර | Math | A | සිල්වා | 077 |
| S03 | C03 | සීතා | කළුතර | Science | A | ජයවර්ධන | 076 |
Second Normal Form — දෙවන සාමාන්ය ස්වරූපය
- 1NF සපුරාලේ
- අර්ධ යැපීම් (Partial Dependencies) නැත
- Non-key attributes, සම්පූර්ණ PK මත රැඳේ
| ශිෂ්ය_ID 🔑 | නම | ලිපිනය |
|---|---|---|
| S01 | කමල් | කොළඹ |
| S02 | නිමල් | ගම්පහ |
| S03 | සීතා | කළුතර |
| කෝර්ස්_ID 🔑 | විෂය_නම |
|---|---|
| C01 | IT |
| C02 | Math |
| C03 | Science |
| ශිෂ්ය_ID 🔑 | කෝර්ස්_ID 🔑 | ශ්රේණිය | ගුරු_නම | ගුරු_දු. |
|---|---|---|---|---|
| S01 | C01 | A | පෙරේරා | 071 |
| S01 | C02 | B | සිල්වා | 077 |
| S02 | C01 | B | පෙරේරා | 071 |
| S03 | C02 | A | සිල්වා | 077 |
| S03 | C03 | A | ජයවර්ධන | 076 |
Third Normal Form — තෙවන සාමාන්ය ස්වරූපය
- 2NF සපුරාලේ
- සංක්රාන්ති යැපීම් (Transitive Dependencies) නැත
- Non-key attribute, Non-key attribute මත රඳා නොපවතී
| ශිෂ්ය_ID 🔑 | කෝර්ස්_ID 🔑 | ශ්රේණිය | ගුරු_ID |
|---|---|---|---|
| S01 | C01 | A | T01 |
| S01 | C02 | B | T02 |
| S02 | C01 | B | T01 |
| S03 | C02 | A | T02 |
| S03 | C03 | A | T03 |
| ගුරු_ID 🔑 | ගුරු_නම | දුරකතන |
|---|---|---|
| T01 | පෙරේරා | 071 |
| T02 | සිල්වා | 077 |
| T03 | ජයවර්ධන | 076 |
| ශිෂ්ය_ID 🔑 | නම | ලිපිනය |
|---|---|---|
| S01 | කමල් | කොළඹ |
| S02 | නිමල් | ගම්පහ |
| S03 | සීතා | කළුතර |
| කෝර්ස්_ID 🔑 | විෂය_නම |
|---|---|
| C01 | IT |
| C02 | Math |
| C03 | Science |
| ස්වරූපය | නිර්ණායකය | ඉවත් කරන්නේ |
|---|---|---|
| 1NF | Atomic values, No repeating groups | Multi-valued cells |
| 2NF | 1NF + Full dependency | Partial dependencies |
| 3NF | 2NF + No transitive | Transitive dependencies |