5. • Basic set of operation for the relational model.
• These operation enable a user to specify basic retrieval requests.
• The result of a retrieval is a new relation, which can be further
manipulated using operations of same algebra.
•it is important for several reasons:
provides formal foundation for relational
model
used as basis for implementing and
optimizing queries in RDMS
6. No commercial RDBMS in use today
provides an interface for the relational
queries.
•Relational algebra operations can be divided into
UNION
INTERSECTION
SET DIFFERENCE
CARTESIAN PRODUCT
SELECT
PROJECT
JOIN etc.
8. It select certain rows
Syntax :
<selection condition>
(R)
<selection condition> is made up of number of clauses of the form
<attribute name > <comparison op> <attribute name>
OR
<attribute name > <comparison op> <constant value>
{ =,<,>,<=,>=,!= }
9. Lets try. . .
Ex :
(DNO=4 )
(EMPLOYEE)
Ex :
(SALARY>25000)
(EMPLOYEE)
10. Clauses can be connected by the
Boolean operators and, or ,not to from a
general selection condition.
(DNO=4 AND SALARY>25000) OR (DNO=5 AND SALARY>30000)
Answer?????
(EMPLOYEE)
11. SELECT operation is commutative :
<cond1>
(
<cond2>
(R)) =
<cond2>
(
<cond1>
Cascade of SELECT operation:
<cond1>
(
<cond2>
(… (
<condn>
(R)). . . ))
=
(
<cond1> AND <cond2> AND . . . AND <condn>
(R)
(R))
12. It select certain columns
Syntax :
<attribute list >
(R)
Duplicate elimination : it removes any duplicate
tuples , and we get a valid relation .
13. What is the
resultant table ???
•
•
SEX, SALARY(EMPLOYEE)
,Lname,Fname,SALARY(EMPLOYEE)
16. We can write the operations as a single algebra
expression by nesting the operation
or
we can apply one operation at a time and create
intermediate result relations.
FNAME, LNAME, SALARY( DNO=5(EMPLOYEE))
Can replace with
DEPCS2
RESULT
DNO=5(EMPLOYEE)
FNAME, LNAME, SALARY
(DEPCS2)
18. A formal RENAME (rho) operations:
• rename either relation name, attribute name or both
s (R)
(B1,B2,…Bn)
S: new table name;
Bn: new attribute name
(R)
s(B1,B2,…Bn)
(R)
19. :R S
: Include all tuples
:Duplicates are eliminated
:R S
: include all tuples that are in both R & S
:R S
: include all tuples that are in R but not in S
25. • Also known as CROSS PRODUCT or CROSS JOIN
• Denoted by X
• syntax :
• tab1 X tab2
• also binary set operations.
• if A has m tuples and B has n tuples then A X B has m * n
tuples .
• Cartesian product followed by SELECT is used to identify
and select related tuples from two relation.
31. • Combine related tuples from two relation into single
tuples.
• denoted by
•R
<JOIN CONDITION> S .
• Consider previous example
RESULT EMPLOYEE X DEPENDENT
FINAL SSN= ESSN (RESULT)
The above can be replaced with
FINAL
EMPLOYEE
SSN=ESSN
DEPENDENT .
34. •A
general join condition is of the form
<condition>AND<condition>AND. . . AND <condition>
Each condition of the form
Ai
ᶱ
Bi
Comparison operator {=,!=,<,>,<=,>=}
•A JOIN operation with such a
general join condition is
called a THETA JOIN
35.
36. • The JOIN where the only comparison operator
used is ‘ = ‘
• It requires that two JOIN attributes have the same
name in both relation .
• if this is not the case then renaming operation done
first.
• This is basically an EQUIJOIN followed by removal of
unnecessary attributes
•Ex: DEPT_LOCS DEPARTMENT * DEPT_LOCATIONS.
38. •A JOIN operation used to combine
data from multiple relations so that
related information can be presented
in a single table. This operations are
also known as inner joins.