Design: Database Design التصميم: تصميم قواعد البيانات

Transforming conceptual models (ERD) into a physical database schema. Normalization, Relations, and Physical File Organizations. تحويل النماذج المفاهيمية (ERD) إلى مخطط قاعدة بيانات مادي. التسوية (Normalization)، العلاقات، وتنظيم الملفات المادي.

Logical vs Physical المنطقي vs المادي Relational Model Relational Model Normalization (1NF, 2NF, 3NF) Normalization (1NF, 2NF, 3NF) Indexing Indexing (الفهرسة) File Hashing File Hashing

Design Process Steps خطوات عملية التصميم

1. Logical Database Modeling 1. النمذجة المنطقية (Logical Modeling)

Describes data using a notation that corresponds to a data organization used by a DBMS (e.g., Relational Tables). وصف البيانات باستخدام تدوين يتوافق مع تنظيم البيانات المستخدم بواسطة الـ DBMS (مثل الجداول العلائقية).

  • Transform ERD into Relations. تحويل الـ ERD إلى علاقات (Relations).
  • Normalization (to remove redundancy). التسوية (Normalization) لإزالة التكرار.
  • Independent of specific hardware. مستقل عن الأجهزة المحددة.

2. Physical Database Design 2. التصميم المادي (Physical Design)

Prescribing the technical specifications for data stored in computer memory. تحديد المواصفات الفنية للبيانات المخزنة في ذاكرة الحاسوب.

  • File organization (Sequential, Indexed). تنظيم الملفات (تسلسلي، مفهرس).
  • Hardware/OS choices. خيارات الأجهزة ونظام التشغيل.
  • Performance tuning. ضبط الأداء (Performance Tuning).

The Relational Model النموذج العلائقي (Relational Model)

Data represented as a set of related tables (Relations). A Relation is a named, two-dimensional table of data. يتم تمثيل البيانات كمجموعة من الجداول المرتبطة. الـ Relation هي جدول بيانات مسمى ثنائي الأبعاد.

Term المصطلح Description الوصف
Primary Key Primary Key An attribute that uniquely identifies each row. (e.g., StudentID). الخاصية التي تعرف كل صف بشكل فريد (مثل: رقم الطالب).
Foreign Key Foreign Key An attribute in a relation that serves as the Primary Key of another relation. Links tables together. خاصية في علاقة تعمل بمثابة Primary Key في علاقة أخرى. تربط الجداول ببعضها.
Composite Key Composite Key A primary key that consists of more than one attribute. مفتاح أساسي يتكون من أكثر من خاصية واحدة.

Normalization التسوية (Normalization)

The process of converting complex data structures into simple, stable data structures. It removes redundancy and prevents anomalies. عملية تحويل هياكل البيانات المعقدة إلى هياكل بسيطة ومستقرة. تزيل التكرار وتمنع الشذوذ (Anomalies).

1

First Normal Form (1NF) 1NF (الصيغة المعيارية الأولى)

Rule: No multi-valued attributes. Every cell must hold a single value (Atomic). القاعدة: لا خصائص متعددة القيم. يجب أن تحتوي كل خلية على قيمة واحدة (Atomic).
Action: Create new rows or tables to handle multiple values. الإجراء: إنشاء صفوف أو جداول جديدة للتعامل مع القيم المتعددة.

2

Second Normal Form (2NF) 2NF (الصيغة المعيارية الثانية)

Rule: 1NF + No Partial Functional Dependencies. Every non-key attribute must depend on the whole primary key. القاعدة: 1NF + لا اعتماد وظيفي جزئي. كل خاصية غير مفتاحية يجب أن تعتمد على المفتاح الأساسي بالكامل.
Action: Split tables if a field depends on only part of a Composite Key. الإجراء: تقسيم الجداول إذا كان الحقل يعتمد على جزء فقط من مفتاح مركب.

3

Third Normal Form (3NF) 3NF (الصيغة المعيارية الثالثة)

Rule: 2NF + No Transitive Dependencies. Non-key attributes must not depend on other non-key attributes. القاعدة: 2NF + لا اعتماد متعدي. الخصائص غير المفتاحية يجب ألا تعتمد على خصائص غير مفتاحية أخرى.
Action: Move transitive fields to their own lookup tables. الإجراء: نقل الحقول المتعدية إلى جداول بحث خاصة بها.

Physical File Organization تنظيم الملفات المادي

1. Sequential 1. تسلسلي (Sequential)

Rows stored in sequence (e.g., by ID). صفوف مخزنة بتسلسل (مثل الترتيب حسب الـ ID).
Pros:المزايا: Fast for full scans.سريع للمسح الكامل.
Cons:العيوب: Slow for random access.بطيء للوصول العشوائي.

2. Indexed 2. مفهرس (Indexed)

Uses an Index file to point to data locations. يستخدم ملف فهرس للإشارة إلى مواقع البيانات.
Pros:المزايا: Fast random access.وصول عشوائي سريع.
Cons:العيوب: Storage overhead.عبء التخزين.

3. Hashed 3. مجزأ (Hashed)

Address is calculated from Key using an algorithm. يتم حساب العنوان من المفتاح باستخدام خوارزمية.
Pros:المزايا: Very fast random access.وصول عشوائي سريع جداً.
Cons:العيوب: Bad for sequential scanning.سيء للمسح التسلسلي.

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

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

TRAP: 2NF vs 3NF فخ: 2NF مقابل 3NF

2NF Issue: Dependency on *part* of the Primary Key (Partial Dependency). Only happens with Composite Keys.
3NF Issue: Dependency on a *non-key* attribute (Transitive Dependency).
مشكلة 2NF: الاعتماد على *جزء* من الـ Primary Key (اعتماد جزئي). يحدث فقط مع المفاتيح المركبة.
مشكلة 3NF: الاعتماد على خاصية *غير مفتاحية* (اعتماد متعدي).

TRAP: Referential Integrity فخ: التكامل المرجعي (Referential Integrity)

"Can a Foreign Key be NULL?"
Yes (usually), unless it's part of the Primary Key.
"Can a Primary Key be NULL?"
NEVER (Entity Integrity Rule).
"هل يمكن أن يكون الـ Foreign Key قيمة NULL؟"
نعم (عادة)، ما لم يكن جزءاً من الـ Primary Key.
"هل يمكن أن يكون الـ Primary Key قيمة NULL؟"
أبداً (قاعدة سلامة الكيان).

SECRET: Transforming M:N سر: تحويل العلاقات M:N

If you see a Many-to-Many (M:N) relationship in an ERD, you MUST create a new relation (table) for it in the Relational Model. The Primary Key of this new table is a composite key of the two original PKs. إذا رأيت علاقة (M:N) في الـ ERD، يجب إنشاء علاقة (جدول) جديدة لها في النموذج العلائقي. المفتاح الأساسي لهذا الجدول الجديد هو مفتاح مركب من المفتاحين الأصليين.

KEY CONCEPT: Denormalization مفهوم أساسي: Denormalization (إلغاء التسوية)

Normalization optimizes for storage and update speed (no anomalies). Denormalization (adding redundancy back) optimizes for read speed (fewer joins). This is a physical design decision. التسوية تحسن التخزين وسرعة التحديث. Denormalization (إعادة التكرار) تحسن سرعة القراءة (عدد أقل من عمليات الـ Join). هذا قرار تصميم مادي.