كل المقررات

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

الفصل 2 (الجزء 2): EER Modeling

Specialization, generalization and weak entities

على طول: الـ EER بيزوّد على الـ ER الوراثة (superclass و subclass) والـ weak entities.

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

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

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

رسوم متحركة

الـ superclass والـ subclasses
الـ weak entity

أمثلة SQL

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

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

المثال ١: superclass وsubclass

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

المثال ٢: Disjoint بقيد CHECK

Sample output (press Run to produce your own):
Error: CHECK constraint failed: kind IN ('student', 'staff')
person_id | name | kind   
----------+------+--------
1         | Mona | student
(1 row)

المثال ٣: Weak entity بـ key مركّبة

Sample output (press Run to produce your own):
Error: UNIQUE constraint failed: dependent.emp_id, dependent.name
emp_id | name | relation
-------+------+---------
1      | Adam | son     
1      | Lina | daughter
(2 rows)

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

اختبار قصير

اختبر فهمك

1. Every student is a person. STUDENT is a ... of PERSON:

2. Generalization goes:

3. A subclass inherits from its superclass:

4. A person who can be both student and staff needs:

5. The key of a weak entity is:

تمارين برمجة

جرّب بإيدك

التمرين 1

اعمل جدول staff بيرث من person (نفس الـ person_id كـ primary key و foreign key) وفيه salary، وضيف موظف واعرضه مع اسمه.

Create a staff table that specializes person (same person_id as primary key and foreign key) with a salary column. Insert one staff member and show them with their name.

(output appears here)

التمرين 2

اعمل weak entity اسمها room جوه building بـ key مركّبة (building_id, room_no) وجرّب تكرر نفس الغرفة.

Create a weak entity room inside building with composite key (building_id, room_no) and try to insert the same room twice.

(output appears here)

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

جامعة بـ specialization وweak entity

الداتا: University sample data: 4 people (2 students, 2 staff) and 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. اعمل person (superclass) وstudent وstaff كـ subclasses بنفس الـ person_id.
  2. اعمل dependent كـ weak entity بـ key (staff_id, name).
  3. ضيف الداتا اللي في الـ starter.
  4. اعرض اسم كل موظف مع راتبه وعدد الـ dependents بتاعه. المتوقع: Lina 9000 و 1، وOmar 8000 و 2.
Expected output (press Run to produce your own):
name | salary | dependents
-----+--------+-----------
Lina | 9000   | 1         
Omar | 8000   | 2         
(2 rows)

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

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

ملف 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 ER and EER modeling.