Lably
Skip to content

Relational algebra

Theory of relational databases

  • 16 min read
  • 9 chapters

Learn it on Lably

The main application of relational algebra is to provide a theoretical foundation for relational databases, particularly query languages for such databases, chief among which is SQL. Relational databases store tabular data represented as relations. Queries over relational databases often likewise return tabular data represented as relations.

The main purpose of relational algebra is to define operators that transform one or more input relations to an output relation. Given that these operators accept relations as input and produce relations as output, they can be combined and used to express complex queries that transform multiple input relations (whose data are stored in the database) into a single output relation (the query results).

Unary operators accept a single relation as input. Examples include operators to filter certain attributes (columns) or tuples (rows) from an input relation. Binary operators accept two relations as input and combine them into a single output relation. For example, taking all tuples found in either relation (union), removing tuples from the first relation found in the second relation (difference), extending the tuples of the first relation with tuples in the second relation matching certain conditions, and so forth.

Introduction

A relation of arity n is a set of n‑tuples. Relational algebra operates on homogeneous sets of tuples, S={(sj1,sj2,...sjn)∣j∈1...m}, where an n‑tuple is a tuple (row; index j) with n 'types of attributes' (or data domains), thus m is the number of rows of tuples in a table and n is the number of columns (and all entries in each column have the same 'type').

A relation also has a unique tuple called the header which gives each column a unique name or attribute inside the relation. Attributes are used in projections and selections.

Sign in to keep reading

8 more chapters are free with a Lably account.

More in Computing and communication