Relational Calculus

Relational calculus is a declarative query language based on mathematical logic that describes “What to retrieve” rather than “How to retrieve it”. It uses predicate logic to specify the desired properties of the result without specifying the procedure to obtain it.

Tuple Relational Calculus (TRC)

TRC uses tuple variables that range over relations. The general form is { t | P(t) } where t is a tuple variable and P(t) is a predicate that must be true.

SAMPLE DATA FOR EXAMPLES

Employee
EmpIDNameDeptIDSalary
1Alice1060000
2Bob2055000
3Carol1070000
4David3040000
5Eve2075000
Department
DeptIDDeptNameLocation
10HRDelhi
20ITMumbai
30FinanceBangalore
Project
ProjIDProjNameDeptID
101Alpha10
102Beta20
103Gamma10
WorksOn
EmpIDProjIDHours
110120
110315
210230
310125
510240

Operations

Selection (Filtering Rows)

Selection retrieves tuples that satisfy a condition using predicates on tuple attributes. Find all employees with salary greater than 60000

EmpIDNameDeptIDSalary
3Carol1070000
5Eve2075000

Projection (Selecting Columns)

Projection extracts specific attributes from tuples using existential quantifiers. Get names and salaries of all employees

NameSalary
Alice60000
Bob55000
Carol70000
David40000
Eve75000

Combined Selection and Projection

Combines filtering and attribute extraction in a single query. Find names of employees in DeptID 10

Name
Alice
Carol

Existential Quantifier (∃)

Existential quantifier checks if there exists at least one tuple satisfying the condition. Find employees who work on at least one project

EmpIDNameDeptIDSalary
1Alice1060000
2Bob2055000
3Carol1070000
5Eve2075000

Universal Quantifier (∀)

Universal quantifier checks if a condition holds for all tuples in a relation. Find employees who work on ALL projects in DeptID 10

EmpIDNameDeptIDSalary
1Alice1060000

Negation (¬)

Negation filters tuples that do not satisfy a given condition. Find employees who do NOT work on any project

EmpIDNameDeptIDSalary
4David3040000

Natural Join

Natural join combines tuples from two relations based on common attributes. Find employee names with their department names

NameDeptName
AliceHR
BobIT
CarolHR
DavidFinance
EveIT

Multiple Conditions

Multiple conditions combine several predicates using logical operators. Find names of employees in IT department with salary > 60000

Name
Eve

Division

Division finds tuples that are related to all tuples in another relation. Find employees who work on ALL projects

EmpIDNameDeptIDSalary

Domain Relational Calculus (DRC)

DRC uses domain variables that range over attribute values. The general form is { ⟨x₁, x₂, ...⟩ | P(x₁, x₂, ...) } where variables represent individual attribute values.

Operations

Selection

Selection filters domain values based on predicates. Find EmpID and Name of employees with salary > 60000

EmpIDName
3Carol
5Eve

Projection

Projection extracts specific domain values from relations. Get all employee names

Name
Alice
Bob
Carol
David
Eve

Join

Join combines domain values from multiple relations based on common attributes. Find employee names and their department locations

NameLocation
AliceDelhi
BobMumbai
CarolDelhi
DavidBangalore
EveMumbai

Existential (∃)

Existential quantifier checks for existence of domain values satisfying conditions. Find names of employees who work on project 101

Name
Alice
Carol

Universal (∀)

Universal quantifier checks if conditions hold for all domain values. Find employees who work on projects with hours ≥ 20 for ALL their assigned projects

EmpIDName
2Bob
3Carol
4David
5Eve