كل المقررات

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

الفصل 4 (الجزء 2): Mapping EER to Relations

Specialization and weak entities

على طول: تحويل الوراثة (superclass و subclass) والـ weak entities.

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

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

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

رسوم متحركة

الـ weak entity

أمثلة SQL

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

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

المثال ١: Weak entity

Sample output (press Run to produce your own):
emp_id | dep_name | age
-------+----------+----
2      | Lina     | 7  
(1 row)

المثال ٢: جدول لكل class

Sample output (press Run to produce your own):
name | gpa
-----+----
Mona | 3.6
(1 row)

المثال ٣: جدول واحد بعمود type

Sample output (press Run to produce your own):
name | kind    | gpa  | office
-----+---------+------+-------
Mona | student | 3.6  | NULL  
Omar | teacher | NULL | B-204 
(2 rows)

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

اختبار قصير

اختبر فهمك

1. The primary key of a weak entity table is:

2. Option A for specialization uses:

3. A single table with a type column has the drawback of:

4. A category (union type) usually needs:

5. ON DELETE CASCADE on a weak entity means:

تمارين برمجة

جرّب بإيدك

التمرين 1

اعمل weak entity اسمه room داخل building. الـ key هو (building_id, room_no).

Create a weak entity room inside building. The key is (building_id, room_no).

(output appears here)

التمرين 2

vehicle superclass وـ car subclass بخيار A. اعرض نوع العربية وعدد أبوابها.

A vehicle superclass and a car subclass using option A. Show the plate and the doors of each car.

(output appears here)

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

شركة: weak entity ووراثة

الداتا: Company sample data: 3 employees, 2 managers, 3 dependents. 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. الرسمة: EMPLOYEE عنده subclass اسمه MANAGER (فيه bonus)، وـ DEPENDENT weak entity تابع للـ EMPLOYEE.
  2. حوّل لـ employee و manager (خيار A) و dependent بـ key مركّب.
  3. ضيف الداتا من الـ starter.
  4. اعرض اسم كل مدير وعدد أبناءه (dependents). المتوقع: Mona = 2 و Omar = 1.
Expected output (press Run to produce your own):
name | dependents
-----+-----------
Mona | 2         
Omar | 1         
(2 rows)

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

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

ملف 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 mapping ER and EER to relations.