كل المقررات

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

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

Entities, attributes, relationships and cardinality

على طول: إزاي نرسم الداتا قبل ما نعمل جداول، بالـ entities والـ relationships.

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

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

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

رسوم متحركة

رسم ER لطلاب ومواد

أمثلة SQL

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

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

المثال ١: Entity وattributes كجدول

Sample output (press Run to produce your own):
student_id | name | year
-----------+------+-----
1          | Mona | 2   
2          | Omar | 3   
(2 rows)

المثال ٢: علاقة واحد لكتير

Sample output (press Run to produce your own):
dept  | employees
------+----------
IT    | 2        
Sales | 1        
(2 rows)

المثال ٣: علاقة كتير لكتير

Sample output (press Run to produce your own):
name | title            | grade
-----+------------------+------
Mona | Databases        | A    
Mona | Machine Learning | B    
Omar | Databases        | B    
(3 rows)

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

اختبار قصير

اختبر فهمك

1. In an ER diagram, a key attribute is shown:

2. A relationship is drawn as:

3. A student can take many courses and a course has many students. The cardinality is:

4. The grade of a student in a course is best an attribute of:

5. Total participation means:

تمارين برمجة

جرّب بإيدك

التمرين 1

اعمل جدولين author و book، وكل كتاب له مؤلف واحد (علاقة واحد لكتير)، وضيف بيانات واعرض اسم المؤلف مع عنوان الكتاب.

Create author and book tables where each book has one author (1:N). Insert data and show author name with book title.

(output appears here)

التمرين 2

جرّب تضيف كتاب بمؤلف مش موجود. إيه اللي بيحصل؟

Try to insert a book whose author does not exist. What happens?

(output appears here)

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

نموذج مكتبة بعلاقة كتير لكتير

الداتا: Library sample data: 3 members, 3 books and 4 loans. 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. الـ entities: member و book. العلاقة LOAN بين الاتنين كتير لكتير وليها attribute اسمه loan_date.
  2. اعمل الجداول الثلاثة، والـ loan بـ primary key من (member_id, book_id).
  3. ضيف الداتا اللي في الـ starter.
  4. اعرض اسم العضو وعنوان الكتاب وتاريخ الاستعارة. المتوقع: 4 صفوف.
Expected output (press Run to produce your own):
name | title      | loan_date 
-----+------------+-----------
Mona | SQL Basics | 2026-01-05
Mona | ER Models  | 2026-01-09
Omar | SQL Basics | 2026-02-01
Nour | Indexes    | 2026-02-10
(4 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 ER and EER modeling.