Database Reference
In-Depth Information
Unary Operations
The projection operation, denoted π C 1 ,...,C n ( R ), returns the columns
C 1 ,...,C n from the relation R . Thus, it can be seen as a vertical partition of
R into two relations: one containing the columns mentioned in the expression
and the other containing the remaining columns. For the relational database
giveninFig. 2.4 , an example of a projection is:
π FirstName, LastName, HireDate ( Employees ) .
This operation returns the three specified attributes from the Employees table.
The selection operation, denoted σ φ ( R ), returns the tuples from the
relation R that satisfy the Boolean condition φ . In other words, it partitions a
table horizontally into two sets of tuples: the ones that do satisfy the condition
and the ones that do not. Therefore, the structure of R is kept in the result.
A selection operation over the relational database given in Fig. 2.4 is:
σ HireDate ' 01/01/1992 ' HireDate ' 31/12/1994 ' ( Employees ) .
This operation returns the employees hired between 1992 and 1994.
Since the result of a relational algebra operation is a relation, it can be used
as input for another operation. To make queries easier to read, sometimes it
is useful to use temporary relations to store intermediate results. We will use
the notation T ← Q to indicate that relation T stores the result of query Q .
Thus, combining the two previous examples, we can ask for the first name,
last name, and hire date of all employees hired between 1992 and 1994. The
query reads:
Temp1
← σ HireDate ' 01/01/1992 ' HireDate ' 31/12/1994 ' ( Employees )
Result
← π FirstName, LastName, HireDate ( Temp1 ) .
The result is given next.
FirstName LastName
HireDate
Nancy
Davolio
1992-05-01
Andrew
Fuller
1992-08-14
Janet
Leverling 1992-04-01
···
···
···
The rename operation, denoted ρ A 1 →B 1 ,...,A k →B k ( R ), returns a relation
where the attributes A 1 ,...,A k in R are renamed to B 1 ,...,B k , respectively.
Therefore, the resulting relation has the same tuples as the relation R ,
although the schema of both relations is different.
 
Search WWH ::




Custom Search