Design II: Advanced Normalization التصميم 2: Advanced Normalization

Going beyond 3NF. Boyce-Codd (BCNF), Multi-valued Dependencies (4NF), and Join Dependencies (5NF). ما بعد 3NF. Boyce-Codd (BCNF)، الاعتماديات متعددة القيم (4NF)، واعتماديات الربط (5NF).

BCNF BCNF Multivalued Dependency (MVD) Multivalued Dependency (MVD) 4NF 4NF Join Dependency (JD) Join Dependency (JD) 5NF 5NF DKNF (Domain-Key) DKNF (Domain-Key)

Boyce-Codd Normal Form (BCNF) Boyce-Codd Normal Form (BCNF)

BCNF is a stricter version of 3NF. It handles a specific anomaly that 3NF misses: dependencies involving prime attributes (keys). BCNF هي نسخة أكثر صرامة من 3NF. تعالج عيباً محدداً يفوته 3NF: الاعتماديات التي تتضمن سمات أولية (مفاتيح).

The Rule القاعدة A relation is in BCNF if for every Functional Dependency (FD) $X \to A$: تكون العلاقة في BCNF إذا كان لكل اعتماد وظيفي (FD) $X \to A$:
$X$ must be a Superkey $X$ يجب أن يكون Superkey
Difference from 3NF الفرق عن 3NF 3NF allows $X \to A$ if $X$ is a superkey OR if $A$ is a Prime Attribute.
BCNF removes the "OR". $X$ MUST be a superkey.
3NF تسمح بـ $X \to A$ إذا كان $X$ هو superkey أو إذا كان $A$ سمة أولية (Prime Attribute).
BCNF تزيل "أو". $X$ يجب أن يكون superkey.

BCNF Violation Example مثال على انتهاك BCNF

Table `LOTS(Property_ID, County_Name, Lot_#)`
Key 1: `{Property_ID}` (Unique ID)
Key 2: `{County_Name, Lot_#}` (Lot numbers are unique per county)
جدول `LOTS(Property_ID, County_Name, Lot_#)`
مفتاح 1: `{Property_ID}` (معرف فريد)
مفتاح 2: `{County_Name, Lot_#}` (أرقام القطع فريدة لكل مقاطعة)

FD1: {County_Name, Lot_#} $\to$ Property_ID
OK (LHS is Key)
FD2: Property_ID $\to$ County_Name
OK (LHS is Key)

If there was an FD `{Property_ID} -> Area` and Property_ID wasn't a key... (Wait, BCNF violations usually involve overlapping keys).
Classic Example: Student, Course, Instructor.
FD: `Instructor -> Course`. Key: `{Student, Course}`.
`Instructor` is NOT a superkey, but determines `Course` (a prime attribute). Valid in 3NF, Invalid in BCNF.
إذا كان هناك FD `{Property_ID} -> Area` و Property_ID لم يكن مفتاحاً... (انتهاكات BCNF عادة تتضمن مفاتيح متداخلة).
مثال كلاسيكي: طالب، مقرر، مدرس.
FD: `Instructor -> Course`. المفتاح: `{Student, Course}`.
`Instructor` ليس superkey، لكنه يحدد `Course` (سمة أولية). صالح في 3NF، غير صالح في BCNF.

Fourth Normal Form (4NF) Fourth Normal Form (4NF)

4NF deals with Multivalued Dependencies (MVDs). 4NF يتعامل مع Multivalued Dependencies (MVDs).

Multivalued Dependency ($X \twoheadrightarrow Y$) Multivalued Dependency ($X \twoheadrightarrow Y$)

Occurs when $X$ determines a set of values for $Y$, and this set is independent of other attributes ($Z$).
Notation: $X \twoheadrightarrow Y$
Read: "X multidetermines Y".
يحدث عندما يحدد $X$ مجموعة من القيم لـ $Y$، وهذه المجموعة مستقلة عن السمات الأخرى ($Z$).
الرمز: $X \twoheadrightarrow Y$
يقرأ: "X يحدد بشكل متعدد Y".

4NF Rule قاعدة 4NF

A relation is in 4NF if for every nontrivial MVD $X \twoheadrightarrow Y$, $X$ is a Superkey.
Basically: Don't put two independent multivalued facts (e.g., Employee's Skills and Employee's Children) in the same table.
تكون العلاقة في 4NF إذا كان لكل MVD غير بديهي (nontrivial) $X \twoheadrightarrow Y$، فإن $X$ هو Superkey.
ببساطة: لا تضع حقيقتين متعددتي القيم ومستقلتين (مثل مهارات الموظف وأطفال الموظف) في نفس الجدول.

Problem: The "EMP" Table المشكلة: جدول "EMP"

Table `EMP(Ename, Pname, Dname)` where an employee works on many Projects (Pname) and has many Dependents (Dname).
These two are independent.
جدول `EMP(Ename, Pname, Dname)` حيث يعمل الموظف في عدة مشاريع (Pname) ولديه عدة معالين (Dname).
هذان الاثنان مستقلان.

Smith
ProjectX
John (Son)
Smith
ProjectY
John (Son)
Smith
ProjectX
Alice (Dau)
Smith
ProjectY
Alice (Dau)

Redundancy! Every project is repeated for every dependent. This is a violation of 4NF.
Solution: Decompose into `(Ename, Pname)` and `(Ename, Dname)`.
تكرار! كل مشروع يتكرر لكل معال. هذا انتهاك لـ 4NF.
الحل: فكك الجدول إلى `(Ename, Pname)` و `(Ename, Dname)`.

Fifth Normal Form (5NF) Fifth Normal Form (5NF)

Join Dependencies (JD) Join Dependencies (JD)

5NF deals with cases where a relation can be decomposed into 3 (or more) tables, but cannot be decomposed into just 2 without losing information (spurious tuples). This is rare. 5NF تتعامل مع الحالات التي يمكن فيها تفكيك العلاقة إلى 3 (أو أكثر) جداول، ولكن لا يمكن تفكيكها إلى جدولين فقط دون فقدان المعلومات (صفوف زائفة). هذا نادر.

Definition (Project-Join NF): التعريف (Project-Join NF): A relation is in 5NF if every Join Dependency is implied by the candidate keys.
Basically: If you can losslessly decompose a table into smaller tables, you must do so unless the join is already enforced by a key.
تكون العلاقة في 5NF إذا كانت كل Join Dependency ضمنية بواسطة الـ candidate keys.
ببساطة: إذا كان بإمكانك تفكيك جدول إلى جداول أصغر دون فقدان البيانات (losslessly)، فيجب عليك فعل ذلك ما لم يكن الربط مفروضاً بالفعل بواسطة مفتاح.

The Ultimate: DKNF القمة: DKNF

Domain-Key Normal Form Domain-Key Normal Form

The "Holy Grail" of normalization.
A relation is in DKNF if every constraint is a logical consequence of Domain Constraints and Key Constraints.
"الكأس المقدسة" للتطبيع.
تكون العلاقة في DKNF إذا كان كل قيد نتيجة منطقية لـ Domain Constraints و Key Constraints.

Theoretical concept. Hard to achieve in practice. مفهوم نظري. صعب التحقيق عملياً.

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

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

TRAP: 3NF vs BCNF Test فخ: اختبار 3NF مقابل BCNF

If you find a dependency $X \to A$ where $X$ is NOT a superkey:
- If $A$ is Prime (part of a key) $\to$ It violates BCNF but is valid 3NF.
- If $A$ is Non-Prime $\to$ It violates both 3NF and BCNF.
إذا وجدت اعتمادية $X \to A$ حيث $X$ ليس superkey:
- إذا كان $A$ أولي (جزء من مفتاح) $\to$ ينتهك BCNF لكنه صالح كـ 3NF.
- إذا كان $A$ غير أولي $\to$ ينتهك كلاً من 3NF و BCNF.

TRAP: 4NF Independence فخ: استقلالية 4NF

For a table to violate 4NF, it must contain TWO or more independent multivalued attributes.
Example: One employee, Many Skills, Many Languages.
Skills and Languages are independent $\to$ Cartesian Product Explosion $\to$ 4NF Violation.
لكي ينتهك جدول 4NF، يجب أن يحتوي على اثنين أو أكثر من السمات متعددة القيم المستقلة.
مثال: موظف واحد، مهارات متعددة، لغات متعددة.
المهارات واللغات مستقلة $\to$ انفجار الضرب الديكارتي $\to$ انتهاك 4NF.

SECRET: Lossless Join سر: Lossless Join

When decomposing a table to fix normal forms (BCNF/4NF), the most critical property to preserve is Lossless Join.
Rule: $R1 \cap R2 \to R1$ OR $R1 \cap R2 \to R2$. (The common attribute must be a key in at least one table).
عند تفكيك جدول لإصلاح الأشكال الطبيعية (BCNF/4NF)، الخاصية الأهم للحفاظ عليها هي Lossless Join (الربط غير الفاقد).
القاعدة: $R1 \cap R2 \to R1$ أو $R1 \cap R2 \to R2$. (السمة المشتركة يجب أن تكون مفتاحاً في جدول واحد على الأقل).

KEY CONCEPT: MVD Triviality مفهوم أساسي: بديهية MVD

An MVD $X \twoheadrightarrow Y$ is trivial if $Y \subseteq X$ or if $X \cup Y$ is the whole relation schema. Trivial MVDs do not violate 4NF. الـ MVD $X \twoheadrightarrow Y$ يكون trivial (بديهي) إذا كان $Y \subseteq X$ أو إذا كان $X \cup Y$ هو مخطط العلاقة بالكامل. الـ MVDs البديهية لا تنتهك 4NF.