كل المقررات

الرئيسية / مقرر قاعدة البيانات / الفصل 7 الجزء 1

الفصل 7 (الجزء 1): Functional Dependencies and Normalization

Redundancy and functional dependencies

على طول: ليه التكرار في الجداول مشكلة، وإيه هي الـ functional dependency.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

تكرار الداتا وتقسيم الجدول

أمثلة SQL

أمثلة قصيرة وبسيطة

الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.

المثال ١: الـ anomaly بتحصل فعلاً

Sample output (press Run to produce your own):
dept_id | dept_name              | rows_n
--------+------------------------+-------
10      | IT                     | 2     
10      | Information Technology | 1     
20      | Math                   | 1     
(3 rows)

المثال ٢: نفحص dependency على الداتا

Sample output (press Run to produce your own):
dept_id | names
--------+------
10      | 1    
20      | 1    
(2 rows)
emp   | depts
------+------
Karim | 1    
Mona  | 1    
Nour  | 1    
Omar  | 1    
(4 rows)

المثال ٣: نقسم الجدول

Sample output (press Run to produce your own):
dept_id | dept_name
--------+----------
10      | IT       
20      | Math     
(2 rows)
emp   | dept_name
------+----------
Karim | IT       
Mona  | IT       
Nour  | Math     
Omar  | IT       
(4 rows)

افتح الموضوع المقابل في صفحة LiU TDDD12

اختبار قصير

اختبر فهمك

1. X -> Y means:

2. An update anomaly happens when:

3. If X -> Y and Y -> Z then:

4. If the closure X+ contains all attributes, X is a:

5. A functional dependency is:

تمارين برمجة

جرّب بإيدك

التمرين 1

في جدول orders(order_id, customer_id, customer_name) افحص هل customer_id -> customer_name متحققة.

In orders(order_id, customer_id, customer_name) check whether customer_id -> customer_name holds.

(output appears here)

التمرين 2

قسّم orders لجدولين: customer وـ orders_small بدون الاسم.

Split orders into customer and a smaller orders table without the name.

(output appears here)

مشروع صغير في آخر المحاضرة

اكتشف الـ dependencies في جدول حقيقي

الداتا: Course registrations sample data: 6 rows. Written for this course (our own data, free to reuse).

License / source: Our own sample data; SQLite is in the public domain. Dataset page

الخطوات

  1. الجدول reg(student, course, teacher, room) جاهز. القاعدة: كل course ليه teacher واحد.
  2. افحص: هل course -> teacher متحققة؟ المتوقع: كل course ليه اسم واحد.
  3. افحص: هل teacher -> room متحققة؟ المتوقع: لأ، Dina ليها غرفتين.
  4. قسّم الجدول لـ course_teacher وـ registration واعرض الأول. المتوقع: 3 صفوف.
Expected output (press Run to produce your own):
course | teachers
-------+---------
DB1    | 1       
ML1    | 1       
OS1    | 1       
(3 rows)
teacher | rooms
--------+------
Dina    | 2    
Sami    | 1    
(2 rows)
course | teacher
-------+--------
DB1    | Dina   
ML1    | Sami   
OS1    | Dina   
(3 rows)

Credits: the topic order follows the lecture list of the course TDDD12 Database Technology at Linköping University (https://www.ida.liu.se/~TDDD12/fo/), whose reading guide is based on the textbook Fundamentals of Database Systems by Elmasri and Navathe. We found no reuse licence on that page, so we link to it and copy nothing from it: the explanations, diagrams, data and code in this lecture are our own. Reference: Elmasri and Navathe, Fundamentals of Database Systems, the chapters on functional dependencies and normalization.