Distributed Database
Management System
Lecture 7
Relational Data Languages
• Two Categories
• Relational Algebra based,
procedural, user is to specify in
terms of certain operations, how
result is to be obtained
• Relational Calculus based, nonprocedural, user only mentions
the relationships among the data
Virtual University of Pakistan
2
• Relational Algebra based,
Procedural
• Relational Calculus based, NonProcedural
• Relational Algebra consists of
Five basic operations
– Selection, Projection, Union, Set
difference and Cartesian Product
Virtual University of Pakistan
3
• Five others
– Intersection, -join, natural join, semi-join and quotient
– Unary and Binary ops
– Union Compatibility
• A horizontal subset
(RELATION)
PREDICATE
• Pred. is based on first- order
predicate calculus
Virtual University of Pakistan
4
• Symbol alphabet
1.Var, constraints, functions,
predicate symbols
2.Parentheses
3.Logical connectors
4.Quantifiers
Virtual University of Pakistan
5
Example
(EMP)
dep = ‘D01’
(dep = ‘D01’) ^ sal < 20000
Virtual University of Pakistan
(EMP)
6
Projection
• Produces vertical subset of a
relation
a1, a2, ..., ak (R)
name, adrs
(STD)
Virtual University of Pakistan
7
Union
•
•
•
All tuples in both the relations
Duplicate tuples rem
Used to insert new records into
relation
Virtual University of Pakistan
8
Set Difference
• (R-S) is the set of tuples in R that
are not in S
• Used for delete op
Virtual University of Pakistan
9
Cartesian Product
•RxS
• Each tuple of one relation is
concatenated with each of other
Virtual University of Pakistan
10
Intersection
• Set of tuples that belong to both
relations
• R S = R – (R-S)
Virtual University of Pakistan
11
Theta Join
• A derivative of RxS
R
S=
(R
x
S)
F
• Predicate here involves attributes
from both tables
Virtual University of Pakistan
12
Natural Join
• An equi-join over two relations
R
S
A
• Attribute name need not to be
same
Virtual University of Pakistan
13