Skip to content
Relational Algebra

Relational Algebra

Introduction

Relational algebra is a procedural query language used to query and manipulate data in relational databases.

It provides a foundation for SQL, and defines operations on relations (or tables) to produce new relations.

The key features are:

  • Operates on one or more relations.
  • Outputs a new relation.
  • Uses a mathematical approach.

It is very important because it:

  • Forms the theoretical foundation of relational databases.
  • Helps in query optimization.
  • Translates user-friendly SQL queries into executable instructions.
  • Promotes a deeper understanding of database operations.

Query Processing

Query processing steps include:

  1. Parsing and translation
  2. Optimization
  3. Evaluation

Basic Relational Algebra Operations

OperationSymbolExample
SELECTσ\sigmaσ\sigma Status = “Active”(Customer)
PROJECTIONπ\piΠ\Pi CustomerName, Status (Customer)
RENAMEρ\rhoρ\rho ${new_name} / ${old_name}
UNION\cupABA \cup B gives all tuples in table AA and BB.
INTERSECTION\capABA \cap B gives all tuples both in AA and BB.
DIFFERENCE-ABA - B gives tuples in AA but not in BB.
CARTESIAN PRODUCT×\timesA×BA \times B gives combinations of columns in AA and BB.
JOIN\JoinNone

Modification of Database

Operations of modifying databases:

  • Deletion
  • Insertion
  • Updating

These operations are expressed using the assignment operator \gets.

Deletion

rrE r \gets r - E

Example:

CustomerCustomer(σ  Status = ‘Active’(Customer)) \text{Customer} \gets \text{Customer} - (\sigma \; \text{Status = `Active'(Customer)})

Insertion

rrE r \gets r \cup E

Example:

CustomerCustomer{1,Name,Active} \text{Customer} \gets \text{Customer} \cup \{1, `\text{Name}', `\text{Active}'\}

Updating

Updating can be expressed by a sequence of deletion and insertion operations.

Last updated on