2NF (Second Normal Form) คืออะไร
ขั้นตอนที่ 2 ของ Normalization ตารางต้องอยู่ใน 1NF แล้ว และ Non-key Attribute ทุกตัว ต้อง Fully Functionally Dependent บน Primary Key ทั้งหมด (ไม่ใช่แค่ส่วนหนึ่ง)
ตัวอย่าง違反 2NF: ตาราง StudentProject (มี Partial Dependency)
| StudentID | ProjectID | StudentName | ProjectName |
|---|---|---|---|
| S89 | P09 | Olivia | Geo Location |
| S76 | P07 | Jacob | Cluster Exploration |
| S56 | P03 | Ava | IoT Devices |
| S92 | P05 | Alexandra | Cloud Deployment |
PK = {StudentID, ProjectID} (Composite Key)
- StudentName ขึ้นกับ StudentID เดียว → Partial Dependency
- ProjectName ขึ้นกับ ProjectID เดียว → Partial Dependency
→ 違反 2NF
แก้ไขเป็น 2NF: แยกตาราง
StudentInfo (StudentID, ProjectID, StudentName)
| StudentID | ProjectID | StudentName |
|---|---|---|
| S89 | P09 | Olivia |
| S76 | P07 | Jacob |
| S56 | P03 | Ava |
| S92 | P05 | Alexandra |
ProjectInfo (ProjectID, ProjectName)
| ProjectID | ProjectName |
|---|---|
| P09 | Geo Location |
| P07 | Cluster Exploration |
| P03 | IoT Devices |
| P05 | Cloud Deployment |
สรุป: 2NF กำจัด Partial Dependency โดยแยก Non-key Attributes ที่ขึ้นกับส่วนหนึ่งของ PK ไปตารางใหม่ พร้อม FK อ้างอิง