Database Systems

Relational Model & Algebra

Relational Model & Algebra

High-Yield Revision Hub

Master Relational Model & Algebra

Master Relational Algebra, Relational Calculus (TRC & DRC), Joins, Division, Codd's Theorem, and Expressive Power.

Concept Breakdown

Detailed technical explanation

Relational Algebra (RA) is a procedural query language that operates on relations using mathematical operators (Selection, Projection, Union, Difference, Cartesian Product, Renaming, Join, and Division) to produce new relations step-by-step.

Relational Calculus (RC) is a declarative query language specifying 'WHAT' data to retrieve without specifying 'HOW' to compute it. It comes in two flavors: Tuple Relational Calculus (TRC) working on tuple variables, and Domain Relational Calculus (DRC) working on domain attribute variables.

Codd's Theorem proves that Relational Algebra and Safe Relational Calculus are equivalent in expressive power. Any language capable of expressing all queries in Relational Algebra is deemed 'Relationally Complete'. However, neither RA nor basic RC can compute recursive queries or Transitive Closure (e.g., finding all connected nodes in a graph of arbitrary depth).

Key Revision Rules

Essential formulas and core points to memorize

  • 1🔍 Selection (σ): Unary operator that filters rows based on a condition σ_p(R). Preserves schema, commutative σ_c1(σ_c2(R)) = σ_c2(σ_c1(R)), output cardinality ≤ |R|.
  • 2✂️ Projection (π): Unary operator that selects specific columns π_{A1,A2}(R). Automatically removes duplicate tuples because relations are mathematical sets. Not commutative.
  • 3➕ Set Operations (∪, -, ∩, ×): Union (∪), Difference (-), and Intersection (∩) require UNION COMPATIBILITY (same degree and domain-compatible attributes). Cartesian Product (×) combines degree: deg(R)+deg(S), cardinality: |R| * |S|.
  • 4🏷️ Renaming (ρ): Renames relation or attributes ρ_{X(A1..An)}(R) or ρ_{B ← A}(R). Essential for resolving attribute ambiguity in self-joins.
  • 5🔗 Joins (⋈, θ-join, Outer Joins): Natural Join (R ⋈ S) equates all common attributes and removes duplicate join columns. Inner/Theta Join is σ_θ(R × S). Outer Joins (⟕, ⟖, ⟗) preserve non-matching tuples padded with NULLs.
  • 6➗ Division (÷): Represents 'FOR ALL' queries. R(X,Y) ÷ S(Y) yields X values associated with ALL Y values in S. Formula: R ÷ S = π_X(R) - π_X((π_X(R) × S) - R).
  • 7🧮 Relational Calculus: Declarative (non-procedural). Tuple Relational Calculus (TRC: {t | P(t)}) and Domain Relational Calculus (DRC: {<x1..xn> | P(x1..xn)}). Uses quantifiers ∃ (existential) and ∀ (universal).
  • 8⚖️ Expressive Power & Codd's Theorem: Relational Algebra and Safe Relational Calculus (TRC/DRC) have EXACTLY EQUIVALENT expressive power. A language equal to RA is 'Relationally Complete'.
  • 9🛡️ Safe Calculus & Equivalence: A calculus expression is 'Safe' if it produces a finite result containing only values from the domain of the expression. Unsafe example: {t | ¬(t ∈ R)}.
  • 10🚫 Transitive Closure Limitation: Neither Basic Relational Algebra nor Relational Calculus can compute Transitive Closure (e.g., recursive reachability in ancestor graphs). Requires Extended RA (Datalog / WITH RECURSIVE).

Common Exam Mistakes

Where students frequently lose marks

Mistake: Thinking Projection (π) allows duplicate rows in output. Standard Relational Algebra automatically eliminates duplicate rows.
Mistake: Performing Union (∪), Intersection (∩), or Difference (-) on relations with different degrees or domain types. They MUST be Union Compatible.
Mistake: Confusing Natural Join (R ⋈ S) with Cartesian Product (R × S). Natural Join automatically matches common attribute names and removes duplicate column outputs.
Mistake: Writing unsafe relational calculus expressions like {t | ¬(t ∈ R)} which result in an infinite set of tuples.
Mistake: Assuming Relational Algebra can evaluate recursive ancestor/descendant queries. Transitive closure requires recursive extensions like Datalog or SQL WITH RECURSIVE.

Topic Quiz Practice

1 of 10
Question 1

Relational Algebra is a Blank query language that takes two relations as input and produces another relation as an output of the query.