Relations, tuples, attributes and domains, schema vs instance, superkeys, candidate, primary and foreign keys, and the relational algebra — selection, projection, set operations, Cartesian product, renaming, joins (theta, equi, natural, outer), intersection and division — with set semantics, result-size bounds, algebraic equivalences and query trees.
A relation is a set of tuples (rows) over a fixed list of attributes (columns), each attribute taking values from a domain.
Schema: Student(sid, name, dept, cgpa) — the structure. Instance: the current set of tuples.
Degree (arity) = number of attributes; cardinality = number of tuples.
Relations are sets: no duplicate tuples and no inherent order of rows. (SQL tables are bags — duplicates allowed.)
Values are atomic (first normal form).
Keys
Key
Definition
Superkey
a set of attributes whose values uniquely identify each tuple
Candidate key
a minimal superkey (no proper subset is a superkey)
Primary key
the candidate key chosen to identify tuples; cannot be NULL
Alternate key
a candidate key not chosen as primary
Foreign key
attributes referencing the primary key of another (or the same) relation
A relation with n attributes has at most 2n−1 superkeys. If {A} is a candidate key of R(A,B,C), every superset of {A} is a superkey: 2n−1=4 superkeys.
Relational algebra
A procedural query language: each operator takes relations and returns a relation, so operators compose.
Operator
Notation
Result
Selection
σcond(R)
rows satisfying the condition
Projection
πA1,…,Ak(R)
chosen columns, duplicates removed
Union
R∪S
tuples in either (schemas must be union-compatible)
Difference
R−S
tuples in R not in S
Intersection
R∩S
tuples in both
Cartesian product
R×S
all pairs; ∣R∣⋅∣S∣ tuples
Rename
ρT(B1,…)(R)
same tuples, new names
Theta join
R⋈θS=σθ(R×S)
pairs satisfying θ
Equi-join
theta join with only equality conditions
Natural join
R⋈S
equi-join on all common attributes, common columns kept once
Outer joins
⟕, ⟖, ⟗
join plus unmatched tuples padded with NULL
Division
R÷S
values of R's other attributes paired with all of S
Semi-join
R⋉S
tuples of R that have a match in S
Size bounds
Expression
Min tuples
Max tuples
σ(R)
0
∣R∣
π(R)
1 (if R non-empty)
∣R∣
R∪S
max(∣R∣,∣S∣)
∣R∣+∣S∣
R∩S
0
min(∣R∣,∣S∣)
R−S
0
∣R∣
R×S
∣R∣⋅∣S∣
∣R∣⋅∣S∣
R⋈S
0
∣R∣⋅∣S∣
R⋈S, common attribute is a key of S
0
∣R∣
R ⟕ S
∣R∣
∣R∣⋅∣S∣
Division, carefully
For R(X,Y) and S(Y), R÷S={x:∀y∈S,(x,y)∈R}:
R÷S=πX(R)−πX((πX(R)×S)−R).
Read it as: all candidates, minus those that are missing some required y.
Equivalences used by query optimisers
Cascade and commute selections: σp∧q(R)=σp(σq(R))=σq(σp(R)).
Push selections down below joins: σp(R⋈S)=σp(R)⋈S if p uses only R's attributes — filter early, join smaller relations.
Push projections down (keeping join attributes).
Joins are commutative and associative — join order is the optimiser's main choice.
π distributes over ∪ but not over − or ∩.
Pushing the selection below the join shrinks the join input.
Quick revision
Practice questions
GATE-style questions: 4 one-mark and 6 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.
Q1NAT1 mark
Relation R has 4 tuples and relation S has 3 tuples. The number of tuples in R×S is ______.
Q2NAT2 marks
R(A,B)={(1,2),(2,3),(3,2)} and S(B,C)={(2,5),(2,6),(4,7)}. The number of tuples in the natural join R⋈S is ______.
Q3MCQ1 mark
R(A,B)={(1,a),(1,b),(2,a)}. Under relational algebra (set) semantics, πA(R) has
Q4MCQ2 marks
Enrolled(sid,cid) and Course(cid) are relations. The query Enrolled÷Course returns
Q5NAT2 marks
E(sid,cid)={(s1,c1),(s1,c2),(s2,c1),(s3,c1),(s3,c2),(s3,c3)} and C(cid)={c1,c2}. The number of tuples in E÷C is ______.
Q6MSQ2 marks
Which equivalences of relational algebra always hold?
One or more options are correct.
Q7NAT2 marks
R has 10 tuples and S has 5 tuples, and they share exactly one attribute. The maximum possible number of tuples in R⋈S is ______.
Q8MCQ1 mark
In R ⟕ S (left outer join), a tuple of R that matches no tuple of S
Q9NAT2 marks
In R(A,B), attribute B is a NOT NULL foreign key referencing the primary key B of S(B,C). R has 100 tuples and S has 20. The number of tuples in R⋈S is ______.
Q10MCQ1 mark
Which set of operators is relationally complete (can express every relational algebra query)?