UNIHIVE

Study Hub UNIPORT CSC 480

CSC 480 · Database Management

Relational algebra

The procedural query language of the relational model: selection, projection, union, set difference, Cartesian product, rename, and derived operations (intersection, joins, division), with worked queries.

Our notes

2 min read

Idea

Operations take one or two relations and return a relation, so they can be combined (closure). It is procedural: it says how to build the answer step by step. Query optimisers use it internally.

Basic operations

OperationSymbolResult
Selectionσ_condition(R)rows of R meeting the condition
Projectionπ_attributes(R)chosen columns (duplicates removed)
UnionR ∪ Srows in R or S (union-compatible: same attributes and domains)
Set differenceR − Srows in R but not S
Cartesian productR × Severy row of R paired with every row of S
Renameρnew name for a relation or attributes

Derived operations

  • Intersection: R ∩ S = R − (R − S).
  • Theta join: R ⋈_θ S = σ_θ(R × S).
  • Equijoin: a theta join with equality.
  • Natural join R ⋈ S: equijoin on all common attributes, with one copy of each.
  • Outer joins (left, right, full): keep unmatched rows, filling the other side with nulls.
  • Semijoin: rows of R that have a match in S.
  • Division R ÷ S: values in R related to every value in S ("students who registered all 400-level CSC core courses").

Worked queries (running database)

  1. Names of 400-level students:

π_FirstName,Surname(σ_Level=400(Student)).

  1. Titles of courses offered by the Computer Science department:

π_Title(σ_DeptName='Computer Science'(Course ⋈ Department)).

  1. MatNos of students who registered CSC 480 but not CSC 498:

π_MatNo(σ_CourseCode='CSC 480'(Registration)) − π_MatNo(σ_CourseCode='CSC 498'(Registration)).

  1. Students who registered every course in a set C (CourseCode only):

π_MatNo,CourseCode(Registration) ÷ C.

Small numeric check

If R has 3 rows and S has 4 rows, R × S has 12 rows, and a natural join has between 0 and 12. Selection never increases the row count; projection can reduce it (duplicates removed).

Aggregation (extended algebra)

γ_DeptCode; COUNT(MatNo)(Student): number of students per department. Grouping and aggregates are not in Codd's original algebra but are standard extensions (they map to SQL GROUP BY).

Exams usually ask: define each operator; write algebra expressions for English queries; show the result of an expression on small tables; explain the natural join and division; union compatibility.

Common mistake: applying union or difference to relations with different attributes. They must be union-compatible: project both to the same columns first.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 480 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.