Relational Algebra

Relational Algebra

This section begins a study of database programming, that is, how the user can ask queries of the database and can change the contents of the database. Our focus is on the relational model, and especially on a notation for describing queries about the content of relations called

An Algebra of Relational Operations

In order to start our study of operations on relations, we shall learn about a special algebra, called relational algebra that comprises some simple but powerful ways to construct new relations from given relations. When the given relations are stored data, then the constructed

Set Operations on Relations

The three most common operations on sets are union, intersection, and difference. We assume the reader is familiar with these operations, which are described as follows on arbitrary sets R and S:

Selection / Cartesian Product

The selection operator, applied to a relation R, creates a new relation with a subset of R's tuples. The tuples in the resulting relation are those that satisfy some condition C that involves the attributes of R. We denote this operation σc(R). The schema for the resulting relation is the

Natural Joins / Theta-Joins

More frequently than we want to take the product of two relations, we find a need to join them by pairing only those tuples that match in some way. The simplest kind of match is the natural join of two relations R and S, denoted R x S, in which we pair only those tuples from R

Combining Operations to Form Queries

If all we could do was to write single operations on one or two relations as queries, then relational algebra would not be as useful as it is. On the other hand, relational algebra, like all algebras, allows us to form expressions of arbitrary complexity by applying operators either to

Renaming

To control the names of the attributes used for relations that are constructed by applying relational-algebra operations, it is often convenient to use an operator that clearly renames relations. We shall use the operator 1 to rename a relation R. The resulting relation has precisely the

Dependent and Independent Operations

Some of the operations that we have explained in previous sections can be expressed in terms of other relational-algebra operations. For instance, intersection can be expressed in terms of set difference:

A Linear Notation for Algebraic Expressions

In Combining Operations to Form Queries we used trees to represent complicated expressions of relational algebra. Another option is to invent names for the temporary relations that correspond to the interior nodes of the tree and write a sequence of assignments that create a

Relational Operations on Bags

While a set of tuples (i.e., a relation) is a simple, natural model of data as it might appear in a database, commercial database systems rarely, if ever, are based entirely on sets. In some situations, relations as they appear in database systems are allowed to have duplicate

Page 1 of 2 Previous 1 2 Next