Dependency (การอ้างอิงทางฟังก์ชัน) ในระบบฐานข้อมูล คือความสัมพันธ์ระหว่างแอตทริบิวต์ (Attributes) 2 ตัวขึ้นไป มี 5 ประเภทหลัก:
1. Functional Dependency (การอ้างอิงทางฟังก์ชัน)
หากค่าของแอตทริบิวต์หนึ่ง (P) กำหนดค่าของอีกแอตทริบิวต์ (Q) ได้อย่างเดียว (Unique) เรียกว่า P → Q
ตัวอย่าง: ตาราง Employee
| EmpID | EmpName | EmpAge |
|---|---|---|
| E01 | Amit | 28 |
| E02 | Rohit | 31 |
EmpID → EmpName เพราะ EmpID เดียวกันต้องมี EmpName เดียวกัน
2. Fully-Functional Dependency (การอ้างอิงทางฟังก์ชันเต็มรูปแบบ)
แอตทริบิวต์ Q เป็น Fully Functionally Dependent บน P ถ้า Q ขึ้นกับ P ทั้งหมด ไม่ใช่แค่ส่วนหนึ่งของ P
ตัวอย่าง: ProjectCost และ EmployeeProject
| ProjectID | ProjectCost |
|---|---|
| 001 | 1000 |
| 002 | 5000 |
| EmpID | ProjectID | Days |
|---|---|---|
| E099 | 001 | 320 |
| E056 | 002 | 190 |
Days ขึ้นกับ {EmpID, ProjectID} ทั้งคู่ (ไม่ใช่แค่ EmpID หรือ ProjectID เดียว) → {EmpID, ProjectID} → Days เป็น Fully Functional Dependency
3. Transitive Dependency (การอ้างอิงแบบ bắcไป)
ถ้า P → Q และ Q → R แล้ว P → R จะเป็น Transitive Dependency (P กำหนด R ผ่าน Q)
4. Multivalued Dependency (การอ้างอิงหลายค่า)
เกิดเมื่อมีแอตทริบิวต์หลายค่าในตารางเดียวกัน ใช้สัญลักษณ์ P →→ Q (Double Arrow)
Q และ R เป็น Multivalued Dependency ของ P ถ้า Q และ R เป็นอิสระต่อกัน
5. Partial Dependency (การอ้างอิงบางส่วน)
Non-prime Attribute ขึ้นกับ ส่วนหนึ่ง ของ Candidate Key (Composite Key)
2NF (Second Normal Form) กำจัด Partial Dependency
ตัวอย่าง: StudentProject
| StudentID | ProjectNo | StudentName | ProjectName |
|---|---|---|---|
| S01 | 199 | Katie | Geo Location |
| S02 | 120 | Ollie | Cluster Exploration |
Candidate Key = {StudentID, ProjectNo}
- StudentName ขึ้นกับ StudentID เดียว → Partial Dependency
- ProjectName ขึ้นกับ ProjectNo เดียว → Partial Dependency
แก้ไข: แยกตารางเป็น StudentInfo(StudentID, ProjectNo, StudentName) และ ProjectInfo(ProjectNo, ProjectName)