Relational algebra

Updated: 06/16/2017 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 first 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 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 which appears in any or in all of 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 (σ) - Given a set of data B and a propositional 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, if φ is the propositional formula "gender=female ∨ (eyeColor=Blue ∧ eyeColor=Hazel)", the selection σφ(Friends) would result in a set that contains 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 attributes a1, a2… For instance, the projection πfullName, phoneNumber(addressBook) results in a set that contains only the members of addressBook that have the attributes fullName and phoneNumber.

Language, Operator, Programming terms