ArticleslgStudy

mathematics

Relational algebra

Relational algebra is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Relational algebra rather than just read about it. In short: In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics. The theory was introduced by Edgar F.

Relational algebra — main illustration
Relational algebra — illustration

Key takeaways

  • Relational algebra belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Relational algebra to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Relational algebra from memory before moving on to harder problems.

Reference excerpt

In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics. The theory was introduced by Edgar F. Codd. 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 Relational algebra received little attention outside of pure mathematics until the publication of E.F. Codd's relational model of data in 1970. Codd proposed such an algebra as a basis for database query languages. A relation of arity n is a set of n‑tuples. Relational algebra operates on homogeneous sets of tuples, S = { ( s j 1 , s j 2 , . . . s j n ) ∣ j ∈ 1... m } , {\displaystyle S=\{(s_{j1},s_{j2},...s_{jn})\mid j\in 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.

Set operators

The relational algebra uses set union, set difference, and Cartesian product from set theory, and adds additional constraints to these operators to create new ones. For set union and set difference, the two relations involved must be union-compatible—that is, the two relations must have the same set of attributes. Because set intersection is defined in terms of set union and set difference, the two relations involved in set intersection must also be union-compatible. For the Cartesian product to be defined, the two relations involved must have disjoint headers (i.e. they must not have a common attribute name). In addition, the Cartesian product is defined differently from the one in set theory, in the sense that tuples are considered to be "shallow" for the purposes of the operation. That means the Cartesian product of a set of n-tuples with a set of m-tuples yields a set of "flattened" ( n + m ) {\displaystyle (n+m)} -tuples (whereas basic set theory would have prescribed a set of 2-tuples, each containing an n-tuple and an m-tuple). In relational algebra, the Cartesian product R × S {\displaystyle R\times S} is defined formally as

The cardinality of the Cartesian product is the product of the cardinalities of its factors, that is, |R × S| = |R| × |S|.

Projection

A projection (Π) is a unary operation written as Π a 1 , … , a n ( R ) {\displaystyle \Pi _{a_{1},\ldots ,a_{n}}(R)} where a 1 , … , a n {\displaystyle a_{1},\ldots ,a_{n}} is a set of attribute names. The result of such projection is defined as the set that is obtained when all tuples in R are restricted to the set { a 1 , … , a n } {\displaystyle \{a_{1},\ldots ,a_{n}\}} . Note: when implemented in SQL standard the "default projection" returns a multiset instead of a set, and the Π projection to eliminate duplicate data is obtained by the addition of the DISTINCT keyword.

Selection

A generalized selection (σ) is a unary operation written as σ φ ( R ) {\displaystyle \sigma _{\varphi }(R)} where φ is a propositional formula that consists of atoms as allowed in the normal selection and the logical operators ∧ {\displaystyle \wedge } (and), ∨ {\displaystyle \lor } (or) and ¬ {\displaystyle \neg } (negation). This selection selects all those tuples in R for which φ holds. To obtain a listing of all friends or business associates in an address book, the selection might be written as

… excerpt ends here. Continue reading the full article.

Illustrations

Relational algebra illustration

Worked examples

Example 1 — a first encounter with Relational algebra

Start with the simplest possible case. Write down what Relational algebra claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Relational algebra before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Relational algebra ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Relational algebra

In research
Relational algebra appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Relational algebra in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Relational algebra is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database management systems, Relational algebra, Relational model, so understanding it makes those chapters shorter.
In everyday life
Look for Relational algebra outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Relational algebra in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Relational algebra means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Relational algebra out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Relational algebra in simple terms?

In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics. The theory was introduced by Edgar F.

Why does Relational algebra matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Relational algebra?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Relational algebra.

Tags

  • Database management systems
  • Relational algebra
  • Relational model

Keep exploring