Download presentation
1
Relational Algebra Relational Calculus
Chapter Five Objectives Fundamental operations in RA Union Set difference Select Project Cartesian Product Relational Calculus COSC 640 Chapter 5
2
Query Languages Procedural Non-Procedural Relational Algebra (RA)
Tuple Relational Calculus Domain Relational Calculus
3
Fundamental Operations in RA
Binary Operations UNION MINUS CARTESIAN PRODUCT Unary Operations SELECT PROJECT
4
Union of R S Union of R S All tuples in R or S Union Compatible
Some degree Attributes of R&S must be the same
5
Union of R S Faculty Name ID Salary Smith 1 70,000 Nelson 3 85,000
Larson 6 62,000 Staff Name ID Salary Smith 1 70,000 Anderson 3 45,000 Faculty U Staff Name ID Salary Smith 1 70,000 Nelson 3 85,000 Larson 6 62,000 Anderson 45,000
6
name (faculty) name (staff)
Union of R S name (faculty) name (staff)
7
Set Difference (MINUS) R - S
Set of tuples in R but not in S Union Compatible Faculty - Staff Name ID Salary Nelson 3 85,000 Larson 6 62,000
8
Intersection: R S Set of of tuples belong to both R & S
Union Compatible Find the list of faculty members who are also staff 70,000 1 Smith Salary ID Name Faculty Staff R S = R – (R – S)
9
Cartesian Product R x S Set of (K1 + K2) tuples: The first K1 tuples are from R. The last K2 tuples are from S Semester S_Num Year Season 1 99 F 2 S 3 00 Semester_Course C_Num S_Num 200 1 250 300 2
10
Cartesian Product R x S List of courses offered in year 99? RxS S_Num
Season C_Num 1 99 F 200 250 300 2 S 3 00 List of courses offered in year 99?
11
Selection (Unary Relation)
Select tuples that satisfy a given predicate major = ‘COSC’ (Student) Result is another relation Conditions are relational operator (,, , , ) Logical operators AND (), OR(), NOT()
12
Selection (Unary Relation)
Find all Faculty members which make less than $45,000 salary < 45,000(Faculty) Find all staff who make less than $40,000 and ID > 100 salary < 40,000 AND ID > 100 (Staff) List of number of courses offered in year 99 S_Num = S_Num AND year = 99 (Semester x Semester_Course)
13
Projection (Unary) Select attributes (Pi)
Find the number of faculty that teach COSC courses name( course=‘COSC’(Faculty))
14
Theta Join R S Theta join allows us to combine the selection & the cartesian product into an operation R A B a b c R C D E a b c d e R S A B C D E a b c d If is = It is called Equijoin If the attributes have the same name, the join is called Natural Join
15
Relational Calculus (RC)
Part Two Relational Calculus (RC) Non-procedural Most commercial query language Types: Tuple RC: Variables represent tuples Domain RC: Variables represent values of domain
16
Tuple Relational Calculus:
{ t | P(t)} Examples List of students with GPA > 3 { t | t Є student ^ t[GPA] > 3 } List of students name with GPA > 3 { t | s Є student (t[NAME] = s[NAME] ^ t[GPA] > 3)}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.