Conceptual Design: The ER Model التصميم المفاهيمي: The ER Model

Understanding high-level conceptual data modeling. Entities, Attributes, Relationships, and Weak Entities. فهم نمذجة البيانات المفاهيمية عالية المستوى. Entities, Attributes, Relationships, و Weak Entities.

Entity Types Entity Types Attributes (Key, Composite, Multi) Attributes (Key, Composite, Multi) Relationship Types Relationship Types Cardinality (1:1, 1:N, M:N) Cardinality (1:1, 1:N, M:N) Weak Entity Weak Entity

Design Process Design Process (عملية التصميم)

Database design is not just creating tables. It follows a structured lifecycle. تصميم قاعدة البيانات لا يقتصر فقط على إنشاء الجداول. بل يتبع دورة حياة منظمة.

1 Requirements Collection جمع المتطلبات
2 Conceptual Design (ERD) التصميم المفاهيمي (ERD)
3 Logical Design (Mapping) التصميم المنطقي (Mapping)
4 Physical Design التصميم المادي

Entities & Attributes Entities & Attributes

Entity Type vs Set Entity Type vs Set

  • Entity: Entity: A specific object in the real world (e.g., Employee "John"). كائن محدد في العالم الحقيقي (مثال: الموظف "John").
  • Entity Type: Entity Type: Defines a collection of entities with the same attributes (e.g., EMPLOYEE). Shown as a Rectangular Box. يحدد مجموعة من الكيانات (Entities) التي لها نفس السمات (مثل EMPLOYEE). يظهر كـ مربع مستطيل.
  • Entity Set: Entity Set: The collection of all actual entities at a specific point in time. مجموعة كل الكيانات الفعلية الموجودة في نقطة زمنية محددة.

Types of Attributes أنواع السمات (Attributes)

  • Simple (Atomic):Simple (Atomic): Indivisible (e.g., SSN, Sex). غير قابل للتقسيم (مثل: SSN, الجنس).
  • Composite:Composite: Divided into subparts (e.g., Address $\to$ Street, City). مقسم إلى أجزاء فرعية (مثل: العنوان $\to$ شارع، مدينة).
  • Multi-valued:Multi-valued: Can have multiple values (e.g., Color $\to$ {Red, Black}). Shown as Double Oval. يمكن أن يكون له قيم متعددة (مثل: اللون $\to$ {أحمر، أسود}). يظهر كـ شكل بيضاوي مزدوج.
  • Derived:Derived: Calculated from others (e.g., Age from BirthDate). Shown as Dashed Oval. يتم حسابه من سمات أخرى (مثل: العمر من تاريخ الميلاد). يظهر كـ شكل بيضاوي منقط.
  • Key:Key: Unique identifier. Underlined in text. معرف فريد. تحته خط في النص.

Relationships Relationships (العلاقات)

A Relationship relates two or more distinct entities. Shown as a Diamond. Relationship تربط بين كيانين أو أكثر. تظهر كـ شكل معين (Diamond).

Degree of Relationship Degree of Relationship

  • Unary (Recursive):Unary (Recursive): Entity relates to itself (e.g., Employee supervises Employee). الكيان يرتبط بنفسه (مثل: موظف يشرف على موظف).
  • Binary:Binary: Two entities (e.g., Employee works for Department). Most common. كيانين (مثل: موظف يعمل في قسم). الأكثر شيوعاً.
  • Ternary:Ternary: Three entities (e.g., Supplier supplies Part to Project). ثلاثة كيانات (مثل: مورد يورد قطعة لمشروع).

Constraints Constraints (القيود)

  • Cardinality Ratio: Cardinality Ratio: Max number of relationship instances (1:1, 1:N, M:N). الحد الأقصى لحالات العلاقة (1:1, 1:N, M:N).
  • Participation (Existence Dependency): Participation (الاعتماد في الوجود):
    - Total (Double Line):Total (خط مزدوج): Every entity MUST participate. كل كيان يجب أن يشارك.
    - Partial (Single Line):Partial (خط مفرد): Participation is optional. المشاركة اختيارية.

ER Diagram: Employee Works For Department ER Diagram: Employee Works For Department

erDiagram EMPLOYEE { string SSN PK string Name } DEPARTMENT { int Number PK string Name } EMPLOYEE ||--|{ DEPARTMENT : "WORKS_FOR"

(N side on Employee, 1 side on Department. Employee has Total Participation). (جانب N عند الموظف، جانب 1 عند القسم. الموظف لديه Total Participation).

Weak Entities Weak Entities

Definition التعريف

An entity type that does not have a key attribute of its own.
It must be identified by its relationship to an Owner (Identifying) Entity via an Identifying Relationship.
نوع كيان لا يمتلك سمة مفتاح (Key attribute) خاصة به.
يجب تعريفه من خلال علاقته بـ Owner Entity (كيان مالك) عبر Identifying Relationship.

Notation: الرمز (Notation):
  • Weak Entity:Weak Entity: Double Rectangle. مستطيل مزدوج.
  • Identifying Relationship:Identifying Relationship: Double Diamond. معين مزدوج.
  • Partial Key:Partial Key: Dashed Underline (e.g., Dependent Name). خط متقطع تحت النص (مثال: اسم التابع).

The Exam Vault خزنة الاختبار

Professor's Secrets & Trap Avoidance أسرار البروفيسور وتجنب الفخاخ

TRAP: Cardinality Notation فخ: تدوين Cardinality

(1,1) vs (0,N):
Many students confuse Min/Max notation.
(Min, Max) = (0, 1) means Participation is Partial (0) and Cardinality is 1.
(Min, Max) = (1, N) means Participation is Total (1) and Cardinality is N.
(1,1) vs (0,N):
كثير من الطلاب يخلطون بين تدوين Min/Max.
(Min, Max) = (0, 1) تعني أن الـ Participation جزئية (Partial 0) والـ Cardinality هي 1.
(Min, Max) = (1, N) تعني أن الـ Participation كلية (Total 1) والـ Cardinality هي N.

TRAP: Weak Entity Key فخ: Weak Entity Key

"Does a Weak Entity have a Primary Key?"
Technically No. It has a Partial Key (Discriminator). Its unique identity is formed by (Owner PK + Partial Key).
"هل يمتلك Weak Entity مفتاحاً أساسياً (Primary Key)؟"
تقنياً لا. هو يمتلك Partial Key (مفتاح جزئي). هويته الفريدة تتشكل من (Owner PK + Partial Key).

SECRET: Attribute on Relationship سر: السمة في العلاقة

Attributes don't always belong to Entities.
Example: "Hours Worked". Does it belong to Employee? No. Project? No. It belongs to the WORKS_ON relationship (the intersection of both). This happens in M:N relationships.
السمات لا تنتمي دائماً للكيانات.
مثال: "ساعات العمل". هل تنتمي للموظف؟ لا. للمشروع؟ لا. هي تنتمي لعلاقة WORKS_ON (التقاطع بينهما). هذا يحدث في علاقات M:N.

KEY CONCEPT: Recursive Relationship مفهوم أساسي: Recursive Relationship

When an entity relates to itself (e.g., "Supervision").
Role Names become critical here (e.g., 1 is "Supervisor", N is "Supervisee") to distinguish the participation of the same entity type.
عندما يرتبط الكيان بنفسه (مثال: "الإشراف").
Role Names تصبح حاسمة هنا (مثال: 1 هو "المشرف"، N هو "المُشرف عليه") لتمييز مشاركة نفس نوع الكيان.