Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

Multi-valued Dependency ใน DBMS: ความหมาย ตัวอย่าง และการแก้ไข


Multi-valued Dependency คืออะไร?

เมื่อการมีอยู่ของแถว (Row) หนึ่งหรือมากกว่าในตาราง บ่งชี้ถึงแถวอื่นหนึ่งหรือมากกว่าในตารางเดียวกัน Multi-valued Dependency จึงเกิดขึ้น

ถ้าตารางมีแอตทริบิวต์ P, Q และ R แล้ว Q และ R เป็น multi-valued facts ของ P

แสดงด้วยลูกศรคู่ (Double Arrow):

P ->> Q P ->> R

Multi-valued Dependency จะมีอยู่ก็ต่อเมื่อ Q และ R เป็นแอตทริบิวต์ที่ อิสระต่อกัน (Independent)

ตารางที่มี Multi-valued Dependency จะ ละเมิด 4NF

ตัวอย่าง

<Student>

StudentName CourseDiscipline Activities
AmitMathematicsSinging
AmitMathematicsDancing
YuvrajComputersCricket
AkashLiteratureDancing
AkashLiteratureCricket
AkashLiteratureSinging

จากตารางเห็นว่า นักศึกษา Amit และ Akash สนใจกิจกรรมมากกว่าหนึ่งกิจกรรม

นี่คือ Multi-valued Dependency เพราะ CourseDiscipline ของนักศึกษาอิสระจาก Activities แต่ทั้งคู่อาศัยกับ Student

Multi-valued Dependency คือ:

StudentName ->> CourseDiscipline StudentName ->> Activities

ความสัมพันธ์ข้างต้นละเมิด Fourth Normal Form

เพื่อแก้ไข ให้แบ่งตารางเป็น 2 ตารางแยกกัน และทำลาย Multi-valued Dependency:

<StudentCourse>

StudentName CourseDiscipline
AmitMathematics
AmitMathematics
YuvrajComputers
AkashLiterature
AkashLiterature
AkashLiterature

<StudentActivities>

StudentName Activities
AmitSinging
AmitDancing
YuvrajCricket
AkashDancing
AkashCricket
AkashSinging

ตอนนี้ Multi-valued Dependency ถูกทำลายแล้ว และเรามี Functional Dependencies 2 อัน:

StudentName → CourseDiscipline StudentName → Activities