BCA / B.Tech 10 min read

Relational Algebra

Relational Algebra in DBMS:

Relational Algebra is a procedural query language that takes instances of relations (tables) as input and yields instances of relations as output. It uses operators to perform queries. It forms the theoretical foundation for SQL.

Key Operations in Relational Algebra:
  • Selection (σ): Selects a subset of rows (tuples) from a relation that satisfy a given condition. Corresponds to the `WHERE` clause in SQL.
  • Projection (π): Selects certain columns (attributes) from a relation and discards the other columns. Corresponds to the `SELECT` list in SQL.
  • Union (∪): Combines two relations and returns all unique rows from both. The relations must be compatible (same number of columns and compatible data types).
  • Set Difference (−): Returns all rows that are in the first relation but not in the second.
  • Cartesian Product (×): Combines each row of one table with each row of another table.
  • Join (⨝): Combines rows from two or more tables based on a related column between them. Natural Join is a common type that joins tables based on their common attributes.