Renaming

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  to rename a relation R. The resulting relation has precisely the same tuples as R, but the name of the relation is S. Furthermore, the attributes of the result relation S are named A1, A2, ,An, in order from the left. If we only want to change the name of the relation to S and leave the attributes as they are in R, we can just say .

Example (a) : In "Selection / Cartesian Product" Example (c), we took the product of two relations R and S from "Selection / Cartesian Product" Figure (a) and used the convention that when an attribute appears in both operands, it is renamed by prefixing the relation name to it. These relations R and S are repeated in Figure (a).

Assume, on the other hand, that we do not wish to call the two versions of B by names R.B and S.B; rather we want to continue to use the name B for the attribute that comes from R, and we want to use X as the name of the attribute B coming from S. We can rename the attributes of S so the first is called X. The result of the expression  is a relation named S that looks just like the relation S from "Selection / Cartesian Product" Figure (a), but its first column has attribute X instead of B.

Renaming before taking a product

When we take the product of R with this new relation, there is no conflict of names among the attributes, so no further renaming is done. That is, the result of the expression  is the relation R x S from "Selection / Cartesian Product" Figure (a), except that the five columns are labeled A, B, X, C, and D, from the left. This relation is shown in Figure (a).

As an alternative, we could take the product without renaming, as we did in "Selection / Cartesian Product" Example (c), and then rename the result. The expression  yields the same relation as in Figure (a), with the same set of attributes. But this relation has a name, RS, while the result relation in Figure (a) has no name.


Tags