Relational algebra

Updated: 05/02/2021 by Computer Hope

Relational algebra is a special form of algebra that describes the data stored in relational databases and the query languages used to access that data. It was developed by E. F. Codd at IBM and was formally introduced in 1970. Codd's work became the basis for database query languages, such as SQL (Structured Query Language) and MySQL.

The five primitive operators

  • Set union (∪) - Given multiple sets of data, for instance two sets B and C, the union of the sets B ∪ C is the data that appears in any or in all the sets.
  • Set difference (∖) - Given two sets of data B and C, the difference of the sets B ∖ C is the data that appears in C but does not appear in B.
  • Cartesian product (×) - Given two sets of data B and C, the Cartesian product B × C is the set of all ordered pairs (b, c) where b is a member of B, and c is a member of C.
  • Selection (σ) - Consider a set of data B, and a formula φ that uses the logical operators and (∧) or (∨) and not (¬). The selection σφ(B) results in all members of B for which the formula φ is true. For instance, suppose that φ is the propositional formula gender=female ∨ (eyeColor=Blue ∧ eyeColor=Hazel). The selection σφ(Friends) would result in a set containing all members of Friends who are female and have either blue or hazel eyes.
  • Projection (π) - Given a set of data B and a set of attributes a1, a2…, the projection πa1, a2…(R) is the set of all members of B restricted by the a1, a2… attributes. For instance, the projection πfullName, phoneNumber(addressBook) results in a set containing only the members of addressBook that have the attributes fullName and phoneNumber.

Idempotence, Language, Operator, Programming terms, Projection