كل المقررات

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

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

Normal forms: 1NF, 2NF, 3NF and BCNF

على طول: خطوات تنضيف التصميم: 1NF ثم 2NF ثم 3NF ثم BCNF.

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

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

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

رسوم متحركة

تقسيم الجدول لإزالة الـ dependency

أمثلة SQL

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

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

المثال ١: من 1NF

Sample output (press Run to produce your own):
student | phone
--------+------
Mona    | 0101 
Mona    | 0122 
(2 rows)

المثال ٢: 2NF

Sample output (press Run to produce your own):
course | course_title
-------+-------------
DB1    | Databases   
(1 row)
student | course | grade
--------+--------+------
Mona    | DB1    | A    
Omar    | DB1    | B    
(2 rows)

المثال ٣: 3NF

Sample output (press Run to produce your own):
rows_back
---------
4        
(1 row)

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

اختبار قصير

اختبر فهمك

1. 1NF requires:

2. 2NF is about:

3. emp -> dept_id -> dept_name is a:

4. In BCNF every determinant X must be a:

5. A lossless split means:

تمارين برمجة

جرّب بإيدك

التمرين 1

جدول sale(sale_id, product, product_price) فيه تكرار للسعر. قسّمه لـ product وـ sale_line.

Table sale(sale_id, product, product_price) repeats the price. Split it into product and sale_line.

(output appears here)

التمرين 2

اتأكد إن التقسيم lossless: اعمل join وعدّ الصفوف.

Check that the split is lossless: join and count the rows.

(output appears here)

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

نضّف جدول طلبات بعد 3NF

الداتا: Orders sample data: 6 rows with repeated customer and product info. 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. الجدول flat جاهز. القواعد: customer_id -> customer_name و product_id -> product_title.
  2. اعمل جدول customer وجدول product وجدول order_line (order_id, customer_id, product_id, qty).
  3. اتأكد إن الـ join بيرجّع 6 صفوف.
  4. اعرض اسم كل عميل وعدد الأوردرات. المتوقع: Mona 3 و Omar 2 و Nour 1.
Expected output (press Run to produce your own):
rows_back
---------
6        
(1 row)
customer_name | orders
--------------+-------
Omar          | 2     
Nour          | 1     
Mona          | 3     
(3 rows)

مشروع نهاية الفصل

ملف المشروع العملي للفصل 7

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

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.