DBMS Tutorial chapters (4)
  1. 01Database Concepts & Relational Architecture
  2. 02Functional Dependencies & Normalization
  3. 03Indexing, B+ Trees & NoSQL Systems
  4. 04Transactions & Concurrency Control

Chapter 02

Functional Dependencies & Normalization

5 topics · 1 sections · beginner-friendly study notes · Updated

Share with friends:WhatsAppTelegram

Embed on your site

Free for teachers, schools and blogs. Please keep the attribution link.

Preview

Normalization is the step-by-step process of splitting a badly designed table into smaller good tables, so data is not repeated and updates do not cause errors.

Functional dependencies (FDs) are the rules that guide this process.

Finding candidate keys, checking the highest normal form and testing lossless decomposition are asked in GATE almost every year.

Cleaning up a messy student, order or salary table so that each fact is stored only once.

1

Functional Dependencies

A functional dependency X → Y means that if two rows have the same value of X, they must have the same value of Y. X is the determinant and Y is the dependent.

In short: If you know the roll number, you can find exactly one name. So roll_no → name.

INNER JOIN Matching in BOTH LEFT JOIN ALL Left + Matched Right FULL OUTER JOIN ALL Left + ALL Right
Functional Dependencies & Normalization

Think about it

FDs describe the real business rules of the data. Normalization uses them to decide how to split tables. In a bank, account_no → balance, branch_name. Knowing the account number tells you exactly one balance and one branch.

Think of a college table.

roll_no → name, because one roll number has one name.

But name → roll_no is false, because two students can share a name.

A dependency is trivial when Y is a subset of X (for example AB → A).

The closure of a set X, written X+, is the set of all attributes that can be found from X using the FDs.

To compute X+, start with X, then keep adding the right side of every FD whose left side is already inside the set, until nothing new appears.

If X+ contains all attributes, X is a super key.

Armstrong axioms: reflexivity (if Y ⊆ X then X → Y), augmentation (X → Y gives XZ → YZ), transitivity (X → Y and Y → Z gives X → Z).

Derived rules: union, decomposition and pseudo-transitivity.

Key points

  • Determinant: The left side X of X → Y.
  • Trivial FD: X → Y where Y is a subset of X.
  • Closure X+: All attributes that X can determine.
  • Canonical (minimal) cover: Smallest equivalent set of FDs: single attribute on right, no extra left attributes, no redundant FD.
  • Armstrong axioms are sound and complete.
  • X is a super key exactly when X+ contains all attributes of the relation.
  • Anomalies caused by bad design: insertion, deletion and update anomalies.
2

Candidate Keys Algorithm

Candidate keys can be found by checking attribute closures. Attributes that never appear on the right side of any FD must be in every key. Attributes that appear only on the right side are in no key.

In short: Start with the attributes that nobody else can give you. If they are enough, you have the key. If not, add more attributes one by one.

Keys identify and link rows

Think about it

You need the keys first to decide which attributes are prime. Only then can you say whether a table is in 2NF, 3NF or BCNF.

Step 1: List all attributes.

Step 2: Find attributes that never appear on any right side.

These must be part of every candidate key.

Call the set Core.

Step 3: Compute Core+.

If it contains all attributes, Core is the only candidate key.

Step 4: If not, add one more attribute at a time (then two at a time) and check closures.

Every minimal set whose closure is everything is a candidate key.

Step 5: Attributes that appear only on the left side or on both sides are the ones to try.

Attributes that appear only on the right side never go into a key.

Always check minimality: no smaller subset should also be a key.

Key points

Read more

3

1NF & 2NF Rules

First Normal Form (1NF): every cell holds a single atomic value, with no repeating groups or lists. Second Normal Form (2NF): the table is in 1NF and has no partial dependency, which means no non-prime attribute depends on only a part of a candidate key.

In short: 1NF: one value per cell. 2NF: every detail must depend on the whole key, not just a piece of it.

Think about it

These two rules remove the most common repetition and the update, insertion and deletion anomalies. A college stores student name again and again in each course row. If the name is spelled wrong in one row only, the data becomes inconsistent.

1NF example: a student row with phone = "9810, 9820" breaks 1NF.

Give each phone its own row.

2NF applies only when the key is composite.

Take Enrolment(student_id, course_id, student_name, grade) with key (student_id, course_id).

The FD student_id → student_name is a partial dependency, because name depends on only a part of the key.

This causes repetition: the student name is stored in every course row.

Fix: move student_name into a Student table.

Tables with a single-attribute key are always in 2NF if they are in 1NF.

Key points

  • Atomic value: A value that cannot be split further for the application.
  • Partial dependency: A non-prime attribute depends on part of a composite candidate key.
  • Update anomaly: Changing a fact in one row but not in others.
  • 2NF problem = partial dependency. It needs a composite key.
  • A table whose candidate keys are all single attributes is automatically in 2NF.

Example

Code
Removing a partial dependency:
-- Before: partial dependency student_id -> student_name
-- enrolment(student_id, course_id, student_name, grade)

-- After 2NF
CREATE TABLE student   (student_id INT PRIMARY KEY, student_name VARCHAR(60));
CREATE TABLE enrolment (student_id INT, course_id INT, grade CHAR(2),
  PRIMARY KEY (student_id, course_id));

Advantages of normalization

Less repetition, fewer anomalies, smaller tables, easier updates and better data accuracy.

Disadvantages of normalization

More tables, more joins at query time, and slower reads.

Reporting systems sometimes denormalize on purpose.

4

3NF vs BCNF

Third Normal Form (3NF): for every FD X → A, either X is a super key or A is a prime attribute. Boyce-Codd Normal Form (BCNF): for every non-trivial FD X → Y, X must be a super key.

In short: BCNF is the strict rule: only keys can decide other things. 3NF is a little more relaxed: it also allows a prime attribute on the right side.

Compare two ideas side by side

Think about it

These are the normal forms used in practice. They remove transitive dependencies and the remaining anomalies. Storing student, department and department head in one table repeats the head name for every student. Splitting the table fixes it.

A transitive dependency happens when a non-prime attribute depends on another non-prime attribute, such as student_id → dept_id and dept_id → dept_name.

This breaks 3NF.

Fix: split into Student(student_id, dept_id) and Department(dept_id, dept_name).

Every BCNF table is also in 3NF, but not the other way.

A table can be in 3NF but not BCNF only when a prime attribute depends on a non-key.

Example

R(A, B, C) with FDs AB → C and C → B. Keys are AB and AC.

C → B has B prime, so 3NF holds.

But C is not a super key, so BCNF fails.

Important facts: a lossless and dependency-preserving 3NF decomposition always exists.

BCNF is always lossless, but may not preserve dependencies.

Key points

  • Transitive dependency: Non-prime → non-prime through an intermediate attribute (A → B, B → C).
  • BCNF: Every determinant of a non-trivial FD is a super key.
  • Order of strength: BCNF ⊂ 3NF ⊂ 2NF ⊂ 1NF.
  • Shortcut: if all attributes are prime, the table is in 3NF.
  • If the table has only two attributes, it is always in BCNF.
  • 3NF can always be both lossless and dependency preserving. BCNF is always lossless but not always dependency preserving.
5

Lossless Decomposition

A decomposition of R into R1 and R2 is lossless if joining R1 and R2 gives back exactly the original R, with no missing and no extra (spurious) rows.

In short: After cutting a table into pieces, you should be able to glue the pieces together and get the exact original table.

Normalize: remove bad redundancy

Think about it

Normalization is only safe if we never lose information while splitting tables. If a bank splits Customer and Loan data on a non-key column such as city, joining them back may connect the wrong customers and loans.

Binary test: R is split into R1 and R2.

The split is lossless if (R1 ∩ R2) → R1 or (R1 ∩ R2) → R2 holds, which means the common attributes form a key of at least one part.

Example

R(A, B, C) with A → B split into R1(A, B) and R2(A, C).

The common attribute is A, and A → B, so A is a key of R1.

The split is lossless.

If we split into R1(A, B) and R2(B, C) instead, the common attribute B does not determine A or C. So extra rows can appear after the join.

Dependency preservation is a separate property: every original FD can be checked inside a single smaller table without joining.

Always aim for lossless; dependency preservation is nice to have.

Key points

  • Spurious tuple: A wrong extra row created by joining badly decomposed tables.
  • Dependency preservation: All original FDs can be enforced on the smaller tables.
  • Lossless test for two tables: common attributes must be a super key of R1 or R2.
  • Lossless and dependency preserving are independent properties.

Solved examples

Example 01 · Basic

R(A, B, C, D, E) with FDs A → B, B → C, CD → E. Find A+.

Given Data:
    Required To Find:

    Closure of A

    Formula Applied:—
    Step-by-Step Solution:
    Step 1: Start: A+ = {A}.
    Step 2: A → B, so add B: {A, B}.
    Step 3: B → C, so add C: {A, B, C}.
    Step 4: CD → E needs D, which we do not have. Stop.
    Final Answer: A+ = {A, B, C}

    Approach note: Keep applying FDs until no new attribute can be added.

    Example 02 · Intermediate

    R(A, B, C, D) with FDs AB → C, C → D, D → A. Find all candidate keys and the highest normal form.

    Given Data:
      Required To Find:

      Candidate keys and normal form

      Formula Applied:—
      Step-by-Step Solution:
      Step 1: B never appears on a right side, so B is in every candidate key.
      Step 2: B+ = {B}. Not enough.
      Step 3: AB+: AB → C, C → D. All of A, B, C, D, so AB is a key.
      Step 4: CB+: C → D, D → A, then AB → C. All attributes, so CB is a key.
      Step 5: DB+: D → A, then AB → C, C → D. All attributes, so DB is a key.
      Step 6: Keys: AB, BC, BD. All attributes are prime, so the table is in 3NF.
      Step 7: Check BCNF: C → D has C that is not a super key, so BCNF fails.
      Final Answer: Candidate keys: AB, BC, BD. Highest normal form: 3NF (not BCNF).

      Approach note: If all attributes are prime, 3NF is automatic. Then test each FD for BCNF.

      Example 03 · Intermediate

      Enrolment(student_id, course_id, student_name, grade) has FDs student_id → student_name and (student_id, course_id) → grade. What is the highest normal form?

      Given Data:
        Required To Find:

        Highest normal form and fix

        Formula Applied:—
        Step-by-Step Solution:
        Step 1: Candidate key: (student_id, course_id).
        Step 2: student_name depends on only student_id, a part of the key. This is a partial dependency.
        Step 3: So the table is not in 2NF. It is in 1NF.
        Step 4: Fix: Student(student_id, student_name) and Enrolment(student_id, course_id, grade).
        Final Answer: 1NF. After the split, both tables are in BCNF.

        Approach note: Partial dependency means 2NF is broken.

        Example 04 · Intermediate

        R(A, B, C) with A → B is decomposed into R1(A, B) and R2(A, C). Is it lossless?

        Given Data:
          Required To Find:

          Lossless or not

          Formula Applied:—
          Step-by-Step Solution:
          Step 1: Common attributes: R1 ∩ R2 = {A}.
          Step 2: A → B holds, and B is the rest of R1, so A is a key of R1.
          Step 3: The common attribute is a key of one part, so the join is lossless.
          Final Answer: Yes, the decomposition is lossless.

          Approach note: Common attributes must be a super key of R1 or R2.

          Real-world applications

          DBMS

          Using Functional Dependencies & Normalization in real projects

          Cleaning up a messy student, order or salary table so that each fact is stored only once.

          Mechanism: Write small programs, read errors carefully, then grow complexity only after the basics are solid.

          Common mistakes

          ❌ Myth: Every table in 3NF is also in BCNF.

          Why this is wrong: BCNF is stricter. 3NF allows prime attributes on the right side of a dependency.

          ✅ Verified Truth: BCNF ⊂ 3NF. A table can be in 3NF and still violate BCNF.

          ⚠️ Exam Tip: Look for an FD whose left side is not a super key but the right side is prime.

          ❌ Myth: BCNF decomposition always preserves dependencies.

          Why this is wrong: Some FDs can be spread over two tables after a BCNF split.

          ✅ Verified Truth: BCNF is always lossless but may lose dependency preservation. 3NF can have both.

          ⚠️ Exam Tip: Quote this when asked why 3NF is used in practice.

          ❌ Myth: A lossless decomposition is also dependency preserving.

          Why this is wrong: The two properties are independent.

          ✅ Verified Truth: A split can be lossless but still lose an FD, or preserve FDs but be lossy.

          ⚠️ Exam Tip: Test each property separately.

          Revision notes

          Normalization is the step-by-step process of splitting a badly designed table into smaller good tables, so data is not repeated and updates do not cause errors. Functional dependencies (FDs) are the rules that guide this process.

          High-Yield Quick Revision Points

          1. X → Y: same X means same Y
          2. X+ closure; X is a super key when X+ has all attributes
          3. Attributes never on the right side are in every key
          4. 1NF: atomic cells. 2NF: no partial dependency
          5. 3NF: X is a super key OR A is prime. BCNF: X is a super key
          6. All attributes prime → at least 3NF
          7. Lossless: R1 ∩ R2 is a key of R1 or R2
          8. BCNF always lossless, not always dependency preserving

          Practice questions

          Question 1 · MCQ (GATE)

          R(A, B, C) with FDs A → B and B → C. What is A+?

          Question 2 · MCQ (GATE / semester)

          A partial dependency violates which normal form?

          Question 3 · MCQ (GATE)

          A relation where all attributes are prime is always in at least:

          Question 4 · MCQ (GATE)

          Which statement is TRUE?

          Question 5 · MCQ (GATE)

          R is split into R1 and R2. The join is lossless when R1 ∩ R2 is: