Module 10 · 15 min read · Free chapter
Integrity constraints and normal forms
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.
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. means that whenever two tuples agree on X, they must also agree on Y, so X "determines" Y. says a roll number fixes the name, and says a course has one fee. An FD such as , 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. holds here, because both rows with A = 1 have B = x. fails, because those rows have C = p and C = q, and 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: is a key when 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 , then , which gives the trivial FDs.
- Augmentation: if , then for any set Z.
- Transitivity: if and , then .
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 and into , decomposition turns into and , and pseudotransitivity turns and into .
Applying axioms by hand is slow, so in practice we compute the closure , 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 . For , start with , add B by and add C by ; cannot fire without D, so . For , start with , add B and C as before, and now fires, so , which is all of R.
The closure answers two questions in one line. To test whether follows from F, check whether , so follows but does not. To test whether X is a superkey, check whether 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 , the attributes A and D appear on no right side. Since 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 . Only B is missing from the right sides, and , so B alone is not enough. Adding one attribute at a time gives , and , 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 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 . Splitting gives , , and , with the duplicate dropped. In , B is extraneous because already contains C, so it becomes ; and then is redundant because and give it, so the minimal cover is .
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 is a superkey or A is prime | Transitive dependencies of non-prime attributes |
| BCNF | For every non-trivial , X is a superkey | Every dependency on a non-key |
Example 1: only 1NF. Let R(A, B, C, D) have . A and B appear on no right side and is all of R, so AB is the only key. The FD 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 . The only key is A, a single attribute, so no partial dependency is possible and R is in 2NF. But in , B is not a superkey and C is not prime, so this transitive dependency () breaks 3NF.
Example 3: 3NF but not BCNF. Return to R(A, B, C, D) with and keys AB, BC and BD. Every attribute is prime, so the 3NF condition always holds. But 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. and form a lossless decomposition of R if and only if their common attributes determine all of or all of . 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 , 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 inside (A, B) and inside (A, C, D), so it preserves dependencies. But (A, C, D) has key AC and the partial dependency , 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 and , since each teacher teaches one subject. The keys are (Student, Subject) and (Student, Teacher), so breaks BCNF but not 3NF, because Subject is prime. Splitting into (Teacher, Subject) and (Student, Teacher) is lossless and in BCNF, but the FD 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:
- Define functional dependency and each normal form, with an example relation that is in one form but not the next.
- Normalise a given table step by step up to 3NF or BCNF, showing the keys and the FDs at each step.
- Prove or test properties, such as using Armstrong's axioms to derive an FD or testing a decomposition for lossless join.
- Discuss a trade-off, usually BCNF against 3NF, or normalisation against query speed.
Practice questions (our own, not previous-year questions).
- 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)
- Given R(A, B, C, D, E) with , find all candidate keys and decompose R into BCNF. Check whether your decomposition preserves dependencies. (15 marks)
- 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 , and conclude that AD is the only candidate key.
- Observe that , and all have left sides that are not superkeys, so R is not even in 2NF.
- Split on 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 now spans two tables, so first split on 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.
- 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.
- is grown by firing FDs whose left sides are inside, and X is a superkey when 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 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.