CS2855 Normalisation
CS2855 Database Normalization Revision Notes
1. Functional Dependencies (FDs)
- Definition: A FD ๐ผ โ ๐ฝ asserts that if two tuples agree on ๐ผ, they must agree on ๐ฝ.
- Armstrongโs Axioms:
- Reflexivity: If ๐ฝ โ ๐ผ, then ๐ผ โ ๐ฝ (e.g., AB โ A).
- Augmentation: If ๐ผ โ ๐ฝ, then ๐พ๐ผ โ ๐พ๐ฝ (e.g., A โ C โน AB โ BC).
- Transitivity: If ๐ผ โ ๐ฝ and ๐ฝ โ ๐พ, then ๐ผ โ ๐พ.
2. Closure of FDs
- Closure (Fโบ): All FDs logically implied by a set F.
- Attribute Closure (๐ผโบ): Set of attributes determined by ๐ผ using F.
- Algorithm to Compute ๐ผโบ:
Initialize result = ๐ผ
Repeat:
For each FD ๐ฝ โ ๐พ in F:
If ๐ฝ โ result, add ๐พ to result
Until no more changes
Return result
3. Redundant Attributes & Canonical Cover
- Redundant Attribute: An attribute in an FD that can be removed without changing Fโบ.
- Example: Given F = {A โ C, AB โ CD}, C is redundant in AB โ CD because {A โ C, AB โ D} โน AB โ CD.
- Canonical Cover:
- Decompose FDs to single RHS (e.g., A โ BC becomes A โ B, A โ C).
- Remove redundant LHS attributes (e.g., ABC โ D becomes AB โ D if C is redundant).
- Eliminate redundant FDs (e.g., if A โ B is implied by other FDs).
4. Decomposition
- Lossless Decomposition: Original relation can be recovered by a natural join of sub-relations.
- Check Lossless:
- If (R1 โฉ R2) is a superkey for R1 or R2.
- Dependency Preservation: All FDs in Fโบ can be checked in the decomposed relations.
5. Normal Forms
a) First Normal Form (1NF)
- All attributes are atomic (no multi-valued/composite attributes).
b) Boyce-Codd Normal Form (BCNF)
- Definition: For every non-trivial FD ๐ผ โ ๐ฝ in Fโบ, ๐ผ is a superkey.
- Decomposition Algorithm:
- Find a violating FD ๐ผ โ ๐ฝ (where ๐ผ is not a superkey).
- Decompose into (๐ผ โช ๐ฝ) and (R โ ๐ฝ).
- Repeat until all relations are in BCNF.
c) Third Normal Form (3NF)
- Definition: For every non-trivial FD ๐ผ โ ๐ฝ in Fโบ:
- ๐ผ is a superkey, OR
- ๐ฝ is a prime attribute (part of a candidate key).
- Advantage: Always preserves dependencies.
BCNF vs 3NF
- BCNF eliminates all redundancy but may lose dependencies.
- 3NF compromises to preserve dependencies.
Past Paper Question Types & Solutions
Type 1: Identify Normal Form
Steps:
- List all FDs.
- Find candidate keys.
- For each FD, check:
- BCNF: If ๐ผ is a superkey.
- 3NF: If ๐ฝ is prime or ๐ผ is a superkey.
Example (CS2855-22):
Given R(A,B,C,D) with FDs AB โ C, C โ D:
- Candidate keys: AB (determines C and D via FDs).
- Violating FD: C โ D (C is not a superkey).
- Not in BCNF (C is not a superkey) but satisfies 3NF (D is prime? No โ Check if D is prime).
Type 2: Decompose into BCNF/3NF
Example:
Decompose R(A,B,C,D) with FDs AB โ C, C โ D into BCNF.
- Find violating FD: C โ D (C is not a superkey).
- Decompose:
- R1 = (C,D)
- R2 = (A,B,C)
- Check: R1 is in BCNF (key = C), R2 (key = AB โ C, satisfies BCNF).
Type 3: Check Lossless Join
Example:
Decomposition R1(A,B), R2(B,C) where B โ A.
- R1 โฉ R2 = B.
- B is a key for R1 (B โ A).
- Lossless as B is a key in R1.
Important Notes
- E-R to Relational Model: Translate entities to tables, relationships to foreign keys.
- SQL Queries:
GROUP BY
is used with aggregate functions (SUM, AVG).HAVING
filters groups;WHERE
filters rows.- Example:
1
2
3
4
5SELECT dept, AVG(salary)
FROM employees
WHERE age > 30
GROUP BY dept
HAVING AVG(salary) > 50000; - Transaction ACID: Ensure atomicity, consistency, isolation, durability.
CS2855 Normalisation
https://blog.pandayuyu.zone/2025/05/13/CS2855-Normalisation/