You are on page 1of 8

RELATIONAL ALGEBRA

Relational algebra is one of the two formal query languages associated with the relational
model. Queries in algebra are composed using a collection of operators. A fundamental
property is that every operator in the algebra accepts (one or two) relation instances as
arguments and returns a relation instance as the result.

Selection and Projection

Relational algebra includes operators to select rows from a relation and to

project columns (π). These operations allow us to manipulate data in a single


relation.

Ϭ rating > 8 (S2)


π sname,rating(S2)
Operators

π sname,rating (Ϭ rating > 8 (S2))


Set Operations
 UNION – RUS
 INTERSECTION – RПS
 SET-DIFFERNCE – R – S
 CROSS PRODUCT – RxS (Cartesian product)
S1 U S2

S1ПS2
S1-S2

S1 x S2

Renaming
Introduce a renaming operator p for this purpose. The expression p(R(F), E) takes
an arbitrary relational algebra expression E and returns an instance of a (new)
relation called R.

p(Temp1,Ϭ bid = 103(S2)

Joins

Division
EXAMPLE
1. Find all boats.
2. Find all sailors name with their age.
3. Find all sailors of age less than 20.
4. Find the names of sailors who have reserved a blue boats.
5. Find the colors of boats reserved by Horatio.
6. Find the names of sailors who have reserved an Interlake blue boat.
7. Find the names of sailors 'Who have reserved all boats.
8. Find the names of sailors who have ratings greater than 7.
9. Find the names of sailors who have reserved at least one boat.
10. Find the names of sailors who have reserved a red and a green boat.

You might also like