∑GATE DA Atlas

Integrity Constraints, Functional Dependencies and Normal Forms

Domain, key, entity and referential integrity constraints with cascading actions, update anomalies, functional dependencies and Armstrong's axioms, attribute closure and finding all candidate keys, minimal covers, the normal forms 1NF, 2NF, 3NF and BCNF (and 4NF), lossless-join and dependency-preserving decomposition, and the 3NF synthesis and BCNF decomposition algorithms.

Section 511 practice questions

Integrity constraints

Constraints are rules the DBMS enforces on every insert, update and delete.

ConstraintMeaningSQL
Domainvalues come from the attribute's type/rangetypes, CHECK (age >= 18)
Not nullvalue requiredNOT NULL
Key (uniqueness)no two tuples share the keyPRIMARY KEY, UNIQUE
Entity integrityprimary key attributes are never NULLimplied by PRIMARY KEY
Referential integrityevery foreign key value matches an existing referenced key (or is NULL)FOREIGN KEY ... REFERENCES
General assertions / triggersarbitrary conditions or actionsCHECK, CREATE ASSERTION, triggers

Referential actions when a referenced row is deleted or its key updated: RESTRICT/NO ACTION (reject), CASCADE (propagate), SET NULL, SET DEFAULT. Inserting a referencing row with a non-existent key is always rejected.

Why normalise? Anomalies

A badly designed table EmpDept(eid, ename, dept, dept_head) repeats dept_head for every employee of a department:

  • Update anomaly: changing a department head requires updating many rows (or the data becomes inconsistent).
  • Insertion anomaly: a new department cannot be recorded until it has an employee.
  • Deletion anomaly: deleting the last employee of a department loses the department's head.

Normalisation removes redundancy by decomposing relations using functional dependencies.

Functional dependencies

X→YX \to Y means: any two tuples that agree on XX also agree on YY. It is trivial if Y⊆XY \subseteq X.

Armstrong's axioms (sound and complete):

  1. Reflexivity: Y⊆X⇒X→YY \subseteq X \Rightarrow X \to Y.
  2. Augmentation: X→Y⇒XZ→YZX \to Y \Rightarrow XZ \to YZ.
  3. Transitivity: X→Y, Y→Z⇒X→ZX \to Y,\ Y \to Z \Rightarrow X \to Z.

Derived rules: union (X→Y,X→Z⇒X→YZX \to Y, X \to Z \Rightarrow X \to YZ), decomposition (X→YZ⇒X→YX \to YZ \Rightarrow X \to Y), pseudo-transitivity (X→Y,WY→Z⇒WX→ZX \to Y, WY \to Z \Rightarrow WX \to Z).

Attribute closure — the workhorse

X+X^+ = all attributes functionally determined by XX:

Python
def closure(X, F):                # F: list of (lhs, rhs) attribute strings
    result = set(X)
    changed = True
    while changed:
        changed = False
        for lhs, rhs in F:
            if set(lhs) <= result and not set(rhs) <= result:
                result |= set(rhs)
                changed = True
    return result

Uses: XX is a superkey iff X+X^+ contains all attributes; X→YX \to Y follows from FF iff Y⊆X+Y \subseteq X^+.

Finding candidate keys

Prime attribute: belongs to some candidate key.

Minimal (canonical) cover

An equivalent set of FDs with single attributes on the right, no extraneous attributes on the left, and no redundant FDs. Steps: split right-hand sides; remove extraneous left attributes (is BB in (X−A)+(X - A)^+?); drop FDs implied by the others.

Normal forms

FormRequirementRemoves
1NFatomic values, no repeating groupsmultivalued cells
2NF1NF + no partial dependency of a non-prime attribute on part of a candidate keyredundancy from composite keys
3NFfor every non-trivial X→AX \to A: XX is a superkey or AA is primetransitive dependencies
BCNFfor every non-trivial X→YX \to Y: XX is a superkeyall FD-based redundancy
4NFBCNF + every non-trivial multivalued dependency X↠YX \twoheadrightarrow Y has XX a superkeyindependent multivalued facts

BCNF ⊂ 3NF ⊂ 2NF ⊂ 1NF. Shortcuts: if every candidate key is a single attribute, a 1NF relation is automatically in 2NF; if every attribute is prime, the relation is automatically in 3NF; any relation with exactly two attributes is in BCNF.

Decomposition

Replacing RR by R1,…,RkR_1, \dots, R_k (projections) must satisfy:

Lossless join — joining the pieces gives back exactly RR (no spurious tuples). Binary test: R1∩R2→R1R_1 \cap R_2 \to R_1 or R1∩R2→R2R_1 \cap R_2 \to R_2 (the common attributes form a superkey of one side).

Dependency preservation — every FD can be checked within a single piece: (F1∪⋯∪Fk)+=F+(F_1 \cup \dots \cup F_k)^+ = F^+.

TargetLossless?Dependency preserving?
3NF (synthesis from a minimal cover, plus a key relation if needed)alwaysalways
BCNF (repeatedly split on a violating FD X→YX \to Y into XYXY and R−Y+XR - Y + X)alwaysnot always

Quick revision

Practice questions

GATE-style questions: 3 one-mark and 8 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

Relation R(A,B,C,D,E)R(A, B, C, D, E) has functional dependencies {A→B, BC→D, D→E}\{A \to B,\ BC \to D,\ D \to E\}. The number of candidate keys of RR is ______.

Q2NAT2 marks

Relation R(A,B,C,D)R(A, B, C, D) has functional dependencies {A→B, B→C, C→A}\{A \to B,\ B \to C,\ C \to A\}. The number of candidate keys of RR is ______.

Q3MCQ2 marks

R(A,B,C)R(A, B, C) with functional dependencies {A→B, B→C}\{A \to B,\ B \to C\} is in which highest normal form?

Q4MCQ1 mark

A relation is in Boyce–Codd normal form (BCNF) if, for every non-trivial functional dependency X→YX \to Y that holds on it,

Q5MSQ2 marks

R(A,B,C)R(A, B, C) with F={A→B}F = \{A \to B\} is decomposed into R1(A,B)R_1(A, B) and R2(A,C)R_2(A, C). Which statements are true?

One or more options are correct.

Q6NAT1 mark

For R(A,B,C,D,E)R(A, B, C, D, E) with F={A→C, B→D, CD→E}F = \{A \to C,\ B \to D,\ CD \to E\}, the number of attributes in the closure (AB)+(AB)^+ is ______.

Q7MCQ2 marks

R(A,B,C)R(A, B, C) has functional dependencies {AB→C, C→B}\{AB \to C,\ C \to B\}. Which statement is correct?

Q8MSQ1 mark

Which of the following are among Armstrong's axioms (the three basic inference rules)?

One or more options are correct.

Q9MCQ2 marks

Table Emp has a foreign key dept referencing Dept(dname) declared with ON DELETE CASCADE. When a row of Dept is deleted,

Q10NAT2 marks

Relation R(A,B,C,D)R(A, B, C, D) has AA as its only candidate key. The number of superkeys of RR is ______.

Q11NAT2 marks

Relation R(A,B,C,D,E,F)R(A, B, C, D, E, F) has functional dependencies {AB→C, C→D, D→EF, F→A}\{AB \to C,\ C \to D,\ D \to EF,\ F \to A\}. The number of candidate keys of RR is ______.