Computer Science and IT‹›⌂ 0:00 studied

Module 10 · 15 min read · Free chapter

Integrity constraints and normal forms

In short

A functional dependency X → Y means equal X values force equal Y values. The closure X⁺ finds keys: X is a superkey when X⁺ holds every attribute. 2NF removes partial dependencies, 3NF allows X → A only if X is a superkey or A is prime, and BCNF needs X to be a superkey. 3NF can always be lossless and dependency preserving.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: why one big table goes wrong

A coaching centre keeps one register for everything. Each line has the roll number, the student's name, the course code and the course fee. Fifty students take the Database course, so its fee of ₹4,000 is written fifty times.

Three problems follow, and each has a name. If the fee rises, all fifty lines must change, and if one is missed the register shows two fees for one course; this is an update anomaly. A new course with no students yet cannot be written down at all, because every line needs a roll number; this is an insertion anomaly. If the only student of a course leaves and his line is deleted, the course fee is lost too; this is a deletion anomaly.

The cure is to keep each fact in one place: one table for students, one for courses, and one linking them. But how do we split a table without losing information, and how do we know when to stop? Functional dependencies and normal forms answer these questions with clear rules.

Why it matters. Normalisation is the step between an ER drawing and a working database. It is also one of the most heavily tested topics in GATE, because every answer can be checked with a short calculation.

Integrity constraints and functional dependencies

An integrity constraint is a rule that every valid state of the database must obey, and the DBMS rejects any change that breaks one. Four kinds are basic. Domain constraints require each value to come from its attribute's domain, key constraints forbid two tuples with the same key, entity integrity forbids NULL in a primary key, and referential integrity requires each foreign key to match an existing primary key or be NULL.

What happens when a referenced row is deleted, such as a department that still has employees? By default SQL rejects the delete. With ON DELETE CASCADE the employees are deleted too, and with ON DELETE SET NULL their department column becomes NULL.

A functional dependency (FD) is a constraint of a special kind. X→YX \to Y means that whenever two tuples agree on X, they must also agree on Y, so X "determines" Y. RollNo→Name\mathit{RollNo} \to \mathit{Name} says a roll number fixes the name, and CourseCode→Fee\mathit{CourseCode} \to \mathit{Fee} says a course has one fee. An FD such as AB→AAB \to A, where the right side is inside the left side, is trivial and always true.

Worked example: reading FDs from a table. Take the instance with rows (1, x, p), (1, x, q) and (2, y, p) over attributes A, B and C. A→BA \to B holds here, because both rows with A = 1 have B = x. A→CA \to C fails, because those rows have C = p and C = q, and C→BC \to B also fails, because C = p appears with both x and y.

Notice the direction of the logic. A table can disprove an FD by showing two rows that break it, but it can never prove that an FD always holds, since a future row might break it. FDs come from the meaning of the data, such as the rule that each course has one fee.

Why it matters. FDs are the raw material of normalisation, and keys themselves are FDs: KK is a key when KK determines every attribute. GATE regularly gives a small instance and asks which FDs it satisfies.

Armstrong's axioms and attribute closure

From a few given FDs, many more follow. Three rules, called Armstrong's axioms, generate all of them:

  • Reflexivity: if Y⊆XY \subseteq X, then X→YX \to Y, which gives the trivial FDs.
  • Augmentation: if X→YX \to Y, then XZ→YZXZ \to YZ for any set Z.
  • Transitivity: if X→YX \to Y and Y→ZY \to Z, then X→ZX \to Z.

These rules are sound, meaning they never produce a false FD, and complete, meaning every FD that follows can be produced by them. Three handy rules follow from them. Union turns X→YX \to Y and X→ZX \to Z into X→YZX \to YZ, decomposition turns X→YZX \to YZ into X→YX \to Y and X→ZX \to Z, and pseudotransitivity turns X→YX \to Y and WY→ZWY \to Z into WX→ZWX \to Z.

Applying axioms by hand is slow, so in practice we compute the closure X+X^+, the set of all attributes that X determines. Start with X itself, then scan the FDs, and whenever an FD's left side lies inside the current set, add its right side. Repeat until nothing new is added.

Worked example. Let R(A, B, C, D, E) have F={A→B,B→C,CD→E}F = \{A \to B, B \to C, CD \to E\}. For A+A^+, start with {A}\{A\}, add B by A→BA \to B and add C by B→CB \to C; CD→ECD \to E cannot fire without D, so A+={A,B,C}A^+ = \{A, B, C\}. For (AD)+(AD)^+, start with {A,D}\{A, D\}, add B and C as before, and now CD→ECD \to E fires, so (AD)+={A,B,C,D,E}(AD)^+ = \{A, B, C, D, E\}, which is all of R.

The closure answers two questions in one line. To test whether X→YX \to Y follows from F, check whether Y⊆X+Y \subseteq X^+, so A→CA \to C follows but A→EA \to E does not. To test whether X is a superkey, check whether X+X^+ is all of R, so AD is a superkey of this R.

Why it matters. Closure is the single tool behind keys, minimal covers, normal-form tests and decomposition checks. If you can compute closures quickly and without slips, every later section becomes routine.

Finding candidate keys and the minimal cover

Finding all candidate keys is a favourite GATE question, and one observation does most of the work. An attribute that appears on no right side of any FD can never be determined by others, so it must be part of every candidate key. Start from those attributes and compute their closure.

Worked example 1. In R(A, B, C, D, E) with F={A→B,B→C,CD→E}F = \{A \to B, B \to C, CD \to E\}, the attributes A and D appear on no right side. Since (AD)+(AD)^+ is all of R, AD is a key, and because every key must contain both A and D, AD is the only candidate key.

Worked example 2. Take R(A, B, C, D) with F={AB→C,C→D,D→A}F = \{AB \to C, C \to D, D \to A\}. Only B is missing from the right sides, and B+={B}B^+ = \{B\}, so B alone is not enough. Adding one attribute at a time gives (AB)+={A,B,C,D}(AB)^+ = \{A, B, C, D\}, (BC)+={B,C,D,A}(BC)^+ = \{B, C, D, A\} and (BD)+={B,D,A,C}(BD)^+ = \{B, D, A, C\}, so the candidate keys are AB, BC and BD.

In the second example every attribute belongs to some key, so all four attributes are prime. This will matter in the next section, because a relation in which every attribute is prime is automatically in 3NF. Its superkeys are the sets that contain B and at least one other attribute, so there are 23−1=72^3 - 1 = 7 of them.

The minimal cover is the cleanest equivalent form of F. It is found in three steps, in this order. First, split every right side into single attributes; second, remove any extraneous attribute from a left side; third, remove any FD that follows from the others.

Worked example 3. Let F={A→BC,B→C,A→B,AB→C}F = \{A \to BC, B \to C, A \to B, AB \to C\}. Splitting gives A→BA \to B, A→CA \to C, B→CB \to C and AB→CAB \to C, with the duplicate A→BA \to B dropped. In AB→CAB \to C, B is extraneous because A+A^+ already contains C, so it becomes A→CA \to C; and then A→CA \to C is redundant because A→BA \to B and B→CB \to C give it, so the minimal cover is {A→B,B→C}\{A \to B, B \to C\}.

Why it matters. Candidate keys decide which attributes are prime, and the normal-form tests depend on that. The minimal cover is the input to the 3NF design method, so a mistake here spreads into the whole design.

The normal forms: 1NF, 2NF, 3NF and BCNF

Each normal form forbids one more kind of bad dependency. Think of it as a ladder: a relation on a higher step is automatically on all the steps below.

Form Condition What it removes
1NF All values atomic Lists and repeating groups in a cell
2NF 1NF, and no non-prime attribute depends on part of a candidate key Partial dependencies
3NF For every non-trivial X→AX \to A, X is a superkey or A is prime Transitive dependencies of non-prime attributes
BCNF For every non-trivial X→AX \to A, X is a superkey Every dependency on a non-key

Example 1: only 1NF. Let R(A, B, C, D) have F={AB→C,B→D}F = \{AB \to C, B \to D\}. A and B appear on no right side and (AB)+(AB)^+ is all of R, so AB is the only key. The FD B→DB \to D makes the non-prime D depend on B, which is only part of the key, so R is not in 2NF and its highest normal form is 1NF.

Example 2: 2NF but not 3NF. Let R(A, B, C) have F={A→B,B→C}F = \{A \to B, B \to C\}. The only key is A, a single attribute, so no partial dependency is possible and R is in 2NF. But in B→CB \to C, B is not a superkey and C is not prime, so this transitive dependency (A→B→CA \to B \to C) breaks 3NF.

Example 3: 3NF but not BCNF. Return to R(A, B, C, D) with F={AB→C,C→D,D→A}F = \{AB \to C, C \to D, D \to A\} and keys AB, BC and BD. Every attribute is prime, so the 3NF condition always holds. But C→DC \to D has a left side C that is not a superkey, so R is not in BCNF.

A few shortcuts save time. Any relation with only two attributes is in BCNF. A 1NF relation whose candidate keys are all single attributes is in 2NF. A relation whose attributes are all prime is in 3NF.

Why it matters. "What is the highest normal form of R?" is asked in GATE almost every year. The method is always the same: find all keys, mark prime attributes, then test each FD against 2NF, 3NF and BCNF in turn.

Decomposition: lossless join and dependency preservation

To reach a higher normal form we decompose R into smaller relations. A good decomposition must pass two tests. It must be lossless, so that joining the parts gives back exactly the original table, and it should be dependency preserving, so that every FD can be checked inside a single part.

The lossless test for two parts. R1R_1 and R2R_2 form a lossless decomposition of R if and only if their common attributes R1∩R2R_1 \cap R_2 determine all of R1R_1 or all of R2R_2. In other words, the common attributes must be a superkey of at least one part. If the parts share nothing, or share a non-key, joining them creates extra rows called spurious tuples, which is why such a split is called lossy.

Worked example. Let R(A, B, C, D) have F={A→B,C→D}F = \{A \to B, C \to D\}, so its only key is AC. Splitting into (A, B) and (C, D) is lossy, because the parts share nothing and their join is a Cartesian product. Splitting into (A, B) and (A, C, D) is lossless, because the common attribute A determines B and so is a key of (A, B).

The second split also keeps A→BA \to B inside (A, B) and C→DC \to D inside (A, C, D), so it preserves dependencies. But (A, C, D) has key AC and the partial dependency C→DC \to D, so we split it again into (C, D) and (A, C), which is lossless because C is a key of (C, D). The final design (A, B), (C, D), (A, C) is in BCNF, lossless and dependency preserving.

When BCNF costs a dependency. Let R(Student, Subject, Teacher) have Student Subject→Teacher\mathit{Student}\,\mathit{Subject} \to \mathit{Teacher} and Teacher→Subject\mathit{Teacher} \to \mathit{Subject}, since each teacher teaches one subject. The keys are (Student, Subject) and (Student, Teacher), so Teacher→Subject\mathit{Teacher} \to \mathit{Subject} breaks BCNF but not 3NF, because Subject is prime. Splitting into (Teacher, Subject) and (Student, Teacher) is lossless and in BCNF, but the FD Student Subject→Teacher\mathit{Student}\,\mathit{Subject} \to \mathit{Teacher} can no longer be checked inside one table.

This example shows the general rule. A 3NF decomposition that is both lossless and dependency preserving always exists, and the standard method builds one table from each FD of the minimal cover plus a key if needed. BCNF can always be reached losslessly, but sometimes only by giving up a dependency.

Why it matters. Designers choose between BCNF with a lost check and 3NF with a little redundancy. GATE tests both halves: whether a split is lossless, and whether the FDs survive it.

Descriptive lens: how written papers ask this

Written papers for IT officer posts, state Assistant Programmer exams and university tests ask about normalisation in four ways:

  1. Define functional dependency and each normal form, with an example relation that is in one form but not the next.
  2. Normalise a given table step by step up to 3NF or BCNF, showing the keys and the FDs at each step.
  3. Prove or test properties, such as using Armstrong's axioms to derive an FD or testing a decomposition for lossless join.
  4. Discuss a trade-off, usually BCNF against 3NF, or normalisation against query speed.

Practice questions (our own, not previous-year questions).

  1. Define 2NF, 3NF and BCNF. Give one relation for each of the cases "2NF but not 3NF" and "3NF but not BCNF", with its FDs. (15 marks)
  2. Given R(A, B, C, D, E) with F={A→B,B→C,CD→E}F = \{A \to B, B \to C, CD \to E\}, find all candidate keys and decompose R into BCNF. Check whether your decomposition preserves dependencies. (15 marks)
  3. Using Armstrong's axioms, prove the union rule and the pseudotransitivity rule. (10 marks)

Answer plan for question 2.

  • Note that A and D are on no right side, compute (AD)+=ABCDE(AD)^+ = ABCDE, and conclude that AD is the only candidate key.
  • Observe that A→BA \to B, B→CB \to C and CD→ECD \to E all have left sides that are not superkeys, so R is not even in 2NF.
  • Split on A→BA \to B into (A, B) and (A, C, D, E), and explain that the split is lossless because A is a key of (A, B).
  • Notice that B→CB \to C now spans two tables, so first split on B→CB \to C instead: take (B, C), then (A, B), then (C, D, E) and finally the key table (A, D).
  • Check that each final table is in BCNF and that every FD lives inside one table, so the design is lossless and dependency preserving.

Quick revision

  • Redundancy causes update, insertion and deletion anomalies.
  • Entity integrity forbids NULL in a primary key, and referential integrity ties foreign keys to existing keys.
  • X→YX \to Y means equal X values force equal Y values, and an instance can only disprove an FD.
  • Armstrong's axioms are reflexivity, augmentation and transitivity, and they are sound and complete.
  • X+X^+ is grown by firing FDs whose left sides are inside, and X is a superkey when X+X^+ is all of R.
  • Attributes on no right side belong to every candidate key.
  • A minimal cover has single right sides, no extraneous left attributes and no redundant FDs.
  • 2NF forbids partial dependencies of non-prime attributes, 3NF allows X→AX \to A only if X is a superkey or A is prime, and BCNF needs X to be a superkey.
  • A two-part split is lossless when the common attributes are a key of one part.
  • 3NF can always be lossless and dependency preserving, while BCNF may lose a dependency.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 14 answered

  1. A course's fee is stored in every student row, and a fee change is missed in one row. This is:

  2. Entity integrity requires that:

  3. An instance has rows (1, x, p), (1, x, q) and (2, y, p) over A, B, C. Which FD is NOT violated by it?

  4. Which inference is NOT valid by Armstrong's axioms and their derived rules?

  5. For F={A→B,B→C,CD→E}F = \{A \to B, B \to C, CD \to E\} on R(A, B, C, D, E), A+A^+ is:

  6. X is a superkey of R exactly when:

  7. R(A, B, C, D) has F={AB→C,C→D,D→A}F = \{AB \to C, C \to D, D \to A\}. The candidate keys are:

  8. An attribute that appears on no right side of any FD in F:

  9. A minimal cover of F={A→BC,B→C,A→B,AB→C}F = \{A \to BC, B \to C, A \to B, AB \to C\} is:

  10. R(A, B, C, D) with F={AB→C,B→D}F = \{AB \to C, B \to D\} is in which highest normal form?

  11. R(A, B, C) with F={A→B,B→C}F = \{A \to B, B \to C\} is in which highest normal form?

  12. Which statement is always true?

  13. R(A, B, C, D) has F={A→B,C→D}F = \{A \to B, C \to D\}. Which decomposition is lossless?

  14. Which is guaranteed for some decomposition of any relation?

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the difference between 3NF and BCNF?

Both require X to be a superkey for every non-trivial X → A, but 3NF also allows it when A is a prime attribute.

How do you find the candidate keys of a relation?

Start with attributes that appear on no right side of any FD, compute their closure, and add other attributes until the closure is all of R.

When is a decomposition lossless?

A split into R₁ and R₂ is lossless when the common attributes form a superkey of R₁ or of R₂.

Is BCNF always dependency preserving?

No. BCNF can always be reached losslessly, but sometimes a dependency is lost, while 3NF can always keep every dependency.

More in this module: Databases

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Database Systems (IIT Kanpur, 106104135): functional dependencies and normalisation