



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























1
2
3
other domain values
arguments produces a value in the domain
operators are as described later), we get the relationalrelational
algebra algebra
query and the value
produced as the queryquery resultresult
4
Domain
: set of relations
difference
difference, Cartesian
Cartesian product
product
Derived operators
set intersection
set intersection, division
division, join
join
by describing an algorithm (the sequence in which
operators are applied) for determining the result of
an expression
7
attribute
operator
constant
OR
8
Id> 3000
OR Hobby=‘ hiking’
Id> 3000
AND Id < 3999
NOT( Hobby=‘ hiking’)
Hobby ≠ ‘ hiking’
9
π
attribute list
relation
PersonPerson π
Name,Hobby
(PersonPerson)
1123 John 123 Main stamps
1123 John 123 Main coins
5556 Mary 7 Lake Dr hiking
9876 Bart 5 Pine St stamps
John stamps
John coins
Mary hiking
Bart stamps
Id Name Address Hobby Name Hobby
10
1123 John 123 Main stamps
1123 John 123 Main coins
5556 Mary 7 Lake Dr hiking
9876 Bart 5 Pine St stamps
John 123 Main
Mary 7 Lake Dr
Bart 5 Pine St
Result is a table (no duplicates); can have fewer tuples
than the original
Id Name Address Hobby Name Address
PersonPerson π
Name,Address
(PersonPerson)
13
have the same domain
14
Tables:
Person
Person ( SSN, Name, Address, Hobby )
Professor Professor ( Id, Name, Office, Phone )
are not union compatible.
But
π
Name
Person
Person) and π
Name
Professor
Professor)
are union compatible so
π
Name
Name
(ProfessorProfessor)
makes sense.
15
R and S
S are two relations, R
S is the set of all
concatenated tuples , where x is a tuple in R
and y is a tuple in S
x1 x2 y1 y2 x1 x2 y1 y
x3 x4 y3 y4 x1 x2 y3 y
x3 x4 y1 y
S x3 x4 y3 y
× SS
16
This is not guaranteed with Cartesian product
same name
names A
1
2
n
to the attributes of the n
column relation produced by expression expr use
expr [ A
1
2
n
19
same name – in which case the Cartesian
product is not defined
use new names in join-condition ´.
(thereby disambiguating the names). For instance:
Transcript.Transcript. CrsCode
CrsCode or Teaching.Teaching. CrsCode
CrsCode
R
R
join_condition
R
R
In RR.A , how do we know which R is meant?
20
Employee(
Employee( Name,Id,MngrId,Salary
Name,Id,MngrId,Salary )
Manager(
Manager( Name,Id,Salary
Name,Id,Salary )
π
EmployeeEmployee .Name
EmployeeEmployee
MngrId=Id
AND Salary>Salary
ManagerManager
The join yields a table with attributes:
EmployeeEmployee. Name , EmployeeEmployee. Id , EmployeeEmployee. Salary , MngrId
Manager
Manager. Name , Manager
Manager. Id , Manager
Manager. Salary
21
π
Name,CrsCode
(StudentStudent
Id=StudId
σ
Grade=‘A’
Transcript
Transcript))
Id Name Addr Status
111 John ….. …..
222 Mary ….. …..
333 Bill ….. …..
444 Joe ….. …..
StudId CrsCode Sem Grade
Mary CSE
Bill CSE
The equijoin is used very
frequently since it combines
related data in different relations.
Student
Student
Transcript
Transcript
Equijoin
Equijoin : Join condition is a conjunction of equalities.
22
same name (condition doesn’t have to be explicitly stated)
TranscriptTranscript ( StudId, CrsCode, Sem, Grade )
Teaching (
Teaching ( ProfId, CrsCode, Sem )
Transcript
Transcript Teaching
Teaching =
π
StudId, Transcript.CrsCode, Transcript.Sem, Grade, ProfId
Transcript
Transcript
CrsCode=CrsCode AND Sem=SemSem
Teaching
Teaching )
StudId, CrsCode, Sem, Grade, ProfId
25
1
n
1
m
s
s (B
1
m
r
r/ s
s , with attributes A
1
n
, is the set of all tuples
__ such that for every tuple in s
_s, _ is
in rr
26
27
every student:
π
StudId, CrsCode
( σ
Grade ≠
‘F’
(TranscriptTranscript) )
CrsCode
of all courses taught in spring 2000
π
CrsCode
( σ
Semester=‘S2000’
Teaching
Teaching) )
28
31
SELECT C. CrsName
FROM CourseCourse C, TeachingTeaching T
WHERE C. CrsCode = T. CrsCode AND T. Semester = ‘S2000’
Also equivalent to:
π
CrsName
σ
C CrsCode=T_CrsCode AND Semester=‘_ S2000’
(CourseCourse [ C_CrsCode, DeptId, CrsName, Desc ]
× TeachingTeaching
ProfId, T_CrsCode, Semester