SlideShare a Scribd company logo
Institute of Southern Punjab,
Multan
Mr. Muhammad Nouman Farooq
BSC-H (Computer Science)
MS (Telecomm. and Networks)
Honors:
Magna Cumm Laude Honors Degree
Gold Medalist!
Blog Url: noumanfarooqatisp.wordpress.com
E-Mail: noman.iefr@hotmail.com
Advance Database Systems
Lecture# 5
Relational Algebra & Calculus
Lecture 5: Relational Algebra & Calculus
 Relational Algebra
 Relational Calculus
3
 Relational Algebra
4
Relational Algebra
 It is a language in which we can ask questions (query) to a database.
 The relational algebra is a theoretical language with operations that
work on one or more relations to define another relation without
changing the original relation(s).
 There are many variations of the operations that are included in
relational algebra. Codd (1972) originally proposed eight operations, but
several others have been developed.
 The five fundamental operations in relational algebra are Selection,
Projection, Cartesian product, Union, and Set difference, perform most
of the data retrieval operations that we are interested in.
5
 In addition, there are also the Join, Intersection, and Division Operations,
which can be expressed in terms of the five basic operations. The function
of each operation is illustrated in Figure 4.1 on next slide.
 The Selection and Projection operations are Unary Operations, since they
operate on one relation.
 The other operations work on pairs of relations and are therefore called
Binary Operations.
 In the following definitions on next slides, let R and S be two
relations/tables defined over the attributes:
A = (a1, a2, . . . , aN) and B = (b1, b2, . . . , bM), respectively.
6
Continued…
1. Unary Operations:
1) Selection Operation
2) Projection Operation
2. Set Operations:
1) Union Operation
2) Set Difference Operation
3) Intersection Operation
4) Cartesian Product Operation
7
Continued…
Continued…
8
3. Join Operations:
1) Theta/Equi Join Operation
2) Natural Join Operation
3) Left Outer Join Operation
4) Semi Join Operation
4. Division Operations:
1) Division Operation
5. Aggregate & Grouping Operations:
1. Aggregate Operation
2. Grouping Operation
9
1. Unary Operations:
10
1) Selection or Restriction Operation: -
13
2) Projection Operation: -
15
16
1) Union Operation: -
2. Set Operations:
18
19
2) Set Difference Operation: -
21
22
3) Intersection Operation: -
23
24
25
26
27
4) Cartesian Product Operation: -
29
30
31
32
1) Theta/Equi Join Operation: -
3. Join Operations:
33
34
2) Natural Join Operation: -
35
36
37
3) Left Outer Join Operation: -
38
39
40
4) Semi Join Operation: -
41
42
4. Division Operations:
43
1) Division Operation: -
44
45
5. Aggregate & Grouping Operations:
46
1) Aggregate Operation: -
47
48
49
2) Grouping Operation: -
50
51
52
 Relational Calculus
53
Relational Calculus
 In the relational calculus, there is no description of how to
evaluate a query; a relational calculus query specifies what is to
be retrieved rather than how to retrieve it.
 The relational calculus is not related to differential and integral
calculus in mathematics, but takes its name from a branch of
symbolic logic called predicate calculus. When applied to
databases, it is found in two forms: tuple relational calculus, as
originally proposed by Codd (1972), and domain relational
calculus, as proposed by Lacroix and Pirotte (1977).
54
 In first-order logic or predicate calculus, a predicate is a truth-
valued function with arguments. When we substitute values for
the arguments, the function yields an expression, called a
proposition, which can be either true or false.
For example, the sentences, ‘John White is a member of
staff’ and ‘John White earns more than Ann Beech’ are both
propositions, since we can determine whether they are true or
false. In the first case, we have a function, ‘is a member of staff’,
with one argument (John White); in the second case, we have a
function, ‘earns more than’, with two arguments (John White and
Ann Beech).
55
Continued…
 If a predicate contains a variable, as in ‘x is a member of
staff’, there must be an associated rangefor x. When we
substitute some values of this range for x, the proposition may
be true; for other values, it may be false.
For example, if the range is the set of all people
and we replace x by John White, the proposition ‘John White is a
member of staff’ is true. If we replace x by the name of a person
who is not a member of staff, the proposition is false.
56
Continued…
 If P is a Predicate/Condition, then we can write the set of all x
such that P is true for x, as:
{x | P(x)}
 We may connect predicates by the logical connectives:
∧ (AND), ∨ (OR), and ~ (NOT) to form compound predicates
57
Continued…
 In the tuple relational calculus we are interested in finding tuples
for which a predicate is true. The calculus is based on the use of
tuple variables. A tuple variable is a variable that ‘ranges over’ a
named relation: that is, a variable whose only allowable values
are tuples of the relation. For example, to specify the range of a
tuple variable S as the Staff relation, we write:
Staff(S)
 To express the query ‘Find the set of all tuples S such that
F(S) is true’, we can write:
{S | F(S)}
58
Tuple Relational Calculus
 F is called a formula (well-formed formula).
For example, to express the query ‘Find the staffNo,
fName, lName, position, DOB, salary, and branchNo of all staff
earning more than £10,000’, we can write:
{S | Staff(S) ∧ S.salary > 10000}
 S.salary means the value of the salary attribute for the tuple
variable S. To retrieve a particular attribute, such as salary, we
would write:
{S.salary | Staff(S) ∧ S.salary > 10000}
59
Continued…
 There are two quantifiers we can use with formulae to tell how many
instances the predicate applies to. The existential quantifier ∃ (‘there
exists’) is used in formulae that must be true for at least one instance,
such as:
Staff(S) ∧ (∃B) (Branch(B) ∧ (B.branchNo = S.branchNo) ∧ B.city = ‘London’)
This means, ‘There exists a Branch tuple that has the same branchNo
as the branchNo of the current Staff tuple, S, and is located in London’.
 The universal quantifier ∀ (‘for all’) is used in statements about every
instance, such as:
(∀B) (B.city ≠ ‘Paris’)
This means, ‘For all Branch tuples, the address is not in Paris’.
60
The Existential and Universal Quantifiers
 Tuple variables that are qualified by ∀ or ∃ are called bound variables,
otherwise the tuple variables are called free variables. The only free variables
in a relational calculus expression should be those on the left side of the bar ( |
). For example, in the following query:
{S.fName, S.lName | Staff(S) ∧ (∃B) (Branch(B) ∧ (B.branchNo = S.branchNo) ∧ B.city = ‘London’)}
 S is the only free variable and S is then bound successively to each tuple of Staff.
61
Continued…
62
64
Domain Relational Calculus
65
66
67
68
Chapter Summary
Recommended Readings
Chapter 4 from: -
 Database Systems-A Practical Approach to Design,
Implementation and Management by Thomas Connolly and
Carolyn BEGG, 4th Edition (Page No. 139-162)
69
Summary of Lecture
70
Lecture 5➦
 Relational Algebra
1. Unary Operations:
1) Selection Operation
2) Projection Operation
2. Set Operations:
1) Union Operation
2) Set Difference Operation
3) Intersection Operation
4) Cartesian Product Operation
Summary of Lecture
71
Lecture 5➦
3. Join Operations:
1) Theta/Equi Join Operation
2) Natural Join Operation
3) Left Outer Join Operation
4) Semi Join Operation
4. Division Operations:
1) Division Operation
5. Aggregate & Grouping Operations:
1) Aggregate Operation
2) Grouping Operation
Summary of Lecture
72
Lecture 5➦
 Relational Calculus
1. The Existential and Universal Quantifiers
2. Tuple Relational Calculus
3. Domain Relational Calculus
 END OF LECTURE 5
73

More Related Content

What's hot

Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
Shishir Aryal
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
Normal forms
Normal formsNormal forms
Normal forms
Samuel Igbanogu
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalizationdaxesh chauhan
 
Elmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 pptElmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 ppt
AbhinavPandey274499
 
Database language
Database languageDatabase language
Chapter 2 database environment
Chapter 2 database environmentChapter 2 database environment
Chapter 2 database environment>. <
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
Archit Saxena
 
Database Chapter 2
Database Chapter 2Database Chapter 2
Database Chapter 2
shahadat hossain
 
Codds rule
Codds ruleCodds rule
Codds rule
Alvina Verghis
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
Shubham Dwivedi
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
Pooja Dixit
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mappingShubham Saini
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
Smriti Jain
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
Visakh V
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and Basics
SHIKHA GAUTAM
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Prateek Parimal
 

What's hot (20)

Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
joins in database
 joins in database joins in database
joins in database
 
Normal forms
Normal formsNormal forms
Normal forms
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
 
Elmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 pptElmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 ppt
 
Database language
Database languageDatabase language
Database language
 
Chapter 2 database environment
Chapter 2 database environmentChapter 2 database environment
Chapter 2 database environment
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Database Chapter 2
Database Chapter 2Database Chapter 2
Database Chapter 2
 
Codds rule
Codds ruleCodds rule
Codds rule
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and Basics
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 

Similar to Relational Algebra & Calculus

GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdfGE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
Asst.prof M.Gokilavani
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
VimalSangar1
 
Normalization
NormalizationNormalization
Normalization
Dabbal Singh Mahara
 
Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vb
alldesign
 
A Systematic Approach To Probabilistic Pointer Analysis
A Systematic Approach To Probabilistic Pointer AnalysisA Systematic Approach To Probabilistic Pointer Analysis
A Systematic Approach To Probabilistic Pointer Analysis
Monica Franklin
 
Mc0079 computer based optimization methods--phpapp02
Mc0079 computer based optimization methods--phpapp02Mc0079 computer based optimization methods--phpapp02
Mc0079 computer based optimization methods--phpapp02
Rabby Bhatt
 
GDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision MakingGDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSCSSN
 
1607.01152.pdf
1607.01152.pdf1607.01152.pdf
1607.01152.pdf
AnkitBiswas31
 
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewedBasic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
bob panic
 
Quantitative Analysis Homework Help
Quantitative Analysis Homework HelpQuantitative Analysis Homework Help
Quantitative Analysis Homework Help
Excel Homework Help
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
VeerannaKotagi1
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
z9819898203
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
YashwanthMalviya
 
Essay On Linear Function
Essay On Linear FunctionEssay On Linear Function
Essay On Linear Function
Angie Lee
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
MAT1033.4.5.ppt
MAT1033.4.5.pptMAT1033.4.5.ppt
MAT1033.4.5.ppt
StreetFoodairy
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 

Similar to Relational Algebra & Calculus (20)

GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdfGE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Normalization
NormalizationNormalization
Normalization
 
Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vb
 
A Systematic Approach To Probabilistic Pointer Analysis
A Systematic Approach To Probabilistic Pointer AnalysisA Systematic Approach To Probabilistic Pointer Analysis
A Systematic Approach To Probabilistic Pointer Analysis
 
Mc0079 computer based optimization methods--phpapp02
Mc0079 computer based optimization methods--phpapp02Mc0079 computer based optimization methods--phpapp02
Mc0079 computer based optimization methods--phpapp02
 
GDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision MakingGDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision Making
 
1607.01152.pdf
1607.01152.pdf1607.01152.pdf
1607.01152.pdf
 
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewedBasic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
 
Quantitative Analysis Homework Help
Quantitative Analysis Homework HelpQuantitative Analysis Homework Help
Quantitative Analysis Homework Help
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Essay On Linear Function
Essay On Linear FunctionEssay On Linear Function
Essay On Linear Function
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
MAT1033.4.5.ppt
MAT1033.4.5.pptMAT1033.4.5.ppt
MAT1033.4.5.ppt
 
Miich4 ftests
Miich4 ftestsMiich4 ftests
Miich4 ftests
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 

More from Abdullah Khosa

Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
Abdullah Khosa
 
Mycin presentation
Mycin presentationMycin presentation
Mycin presentation
Abdullah Khosa
 
Policy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise ArchitecturePolicy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise Architecture
Abdullah Khosa
 
Face to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCIFace to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCI
Abdullah Khosa
 
STRATEGIC PAY PLANS
STRATEGIC PAY PLANSSTRATEGIC PAY PLANS
STRATEGIC PAY PLANS
Abdullah Khosa
 
AI services in google
AI services in googleAI services in google
AI services in google
Abdullah Khosa
 
Cloud Artificial Intelligence services
Cloud Artificial Intelligence servicesCloud Artificial Intelligence services
Cloud Artificial Intelligence services
Abdullah Khosa
 
Digital centralization
Digital centralizationDigital centralization
Digital centralization
Abdullah Khosa
 
Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)
Abdullah Khosa
 
The 5th generation (5G)
The 5th generation (5G)The 5th generation (5G)
The 5th generation (5G)
Abdullah Khosa
 
Report of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiumsReport of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Database of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiumsDatabase of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Attitude and behavior
Attitude and behaviorAttitude and behavior
Attitude and behavior
Abdullah Khosa
 
Digital signature
Digital signatureDigital signature
Digital signature
Abdullah Khosa
 
Benefits of Search engine optimization
Benefits of Search engine optimizationBenefits of Search engine optimization
Benefits of Search engine optimization
Abdullah Khosa
 
Physical Database Design & Performance
Physical Database Design & PerformancePhysical Database Design & Performance
Physical Database Design & Performance
Abdullah Khosa
 
Advanced Normalization
Advanced NormalizationAdvanced Normalization
Advanced Normalization
Abdullah Khosa
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
Abdullah Khosa
 
Advance database system(part 7)
Advance database system(part 7)Advance database system(part 7)
Advance database system(part 7)
Abdullah Khosa
 
Advance database system(part 6)
Advance database system(part 6)Advance database system(part 6)
Advance database system(part 6)
Abdullah Khosa
 

More from Abdullah Khosa (20)

Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
 
Mycin presentation
Mycin presentationMycin presentation
Mycin presentation
 
Policy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise ArchitecturePolicy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise Architecture
 
Face to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCIFace to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCI
 
STRATEGIC PAY PLANS
STRATEGIC PAY PLANSSTRATEGIC PAY PLANS
STRATEGIC PAY PLANS
 
AI services in google
AI services in googleAI services in google
AI services in google
 
Cloud Artificial Intelligence services
Cloud Artificial Intelligence servicesCloud Artificial Intelligence services
Cloud Artificial Intelligence services
 
Digital centralization
Digital centralizationDigital centralization
Digital centralization
 
Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)
 
The 5th generation (5G)
The 5th generation (5G)The 5th generation (5G)
The 5th generation (5G)
 
Report of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiumsReport of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiums
 
Database of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiumsDatabase of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiums
 
Attitude and behavior
Attitude and behaviorAttitude and behavior
Attitude and behavior
 
Digital signature
Digital signatureDigital signature
Digital signature
 
Benefits of Search engine optimization
Benefits of Search engine optimizationBenefits of Search engine optimization
Benefits of Search engine optimization
 
Physical Database Design & Performance
Physical Database Design & PerformancePhysical Database Design & Performance
Physical Database Design & Performance
 
Advanced Normalization
Advanced NormalizationAdvanced Normalization
Advanced Normalization
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
 
Advance database system(part 7)
Advance database system(part 7)Advance database system(part 7)
Advance database system(part 7)
 
Advance database system(part 6)
Advance database system(part 6)Advance database system(part 6)
Advance database system(part 6)
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Relational Algebra & Calculus

  • 1. Institute of Southern Punjab, Multan Mr. Muhammad Nouman Farooq BSC-H (Computer Science) MS (Telecomm. and Networks) Honors: Magna Cumm Laude Honors Degree Gold Medalist! Blog Url: noumanfarooqatisp.wordpress.com E-Mail: noman.iefr@hotmail.com
  • 2. Advance Database Systems Lecture# 5 Relational Algebra & Calculus
  • 3. Lecture 5: Relational Algebra & Calculus  Relational Algebra  Relational Calculus 3
  • 5. Relational Algebra  It is a language in which we can ask questions (query) to a database.  The relational algebra is a theoretical language with operations that work on one or more relations to define another relation without changing the original relation(s).  There are many variations of the operations that are included in relational algebra. Codd (1972) originally proposed eight operations, but several others have been developed.  The five fundamental operations in relational algebra are Selection, Projection, Cartesian product, Union, and Set difference, perform most of the data retrieval operations that we are interested in. 5
  • 6.  In addition, there are also the Join, Intersection, and Division Operations, which can be expressed in terms of the five basic operations. The function of each operation is illustrated in Figure 4.1 on next slide.  The Selection and Projection operations are Unary Operations, since they operate on one relation.  The other operations work on pairs of relations and are therefore called Binary Operations.  In the following definitions on next slides, let R and S be two relations/tables defined over the attributes: A = (a1, a2, . . . , aN) and B = (b1, b2, . . . , bM), respectively. 6 Continued…
  • 7. 1. Unary Operations: 1) Selection Operation 2) Projection Operation 2. Set Operations: 1) Union Operation 2) Set Difference Operation 3) Intersection Operation 4) Cartesian Product Operation 7 Continued…
  • 8. Continued… 8 3. Join Operations: 1) Theta/Equi Join Operation 2) Natural Join Operation 3) Left Outer Join Operation 4) Semi Join Operation 4. Division Operations: 1) Division Operation 5. Aggregate & Grouping Operations: 1. Aggregate Operation 2. Grouping Operation
  • 9. 9
  • 10. 1. Unary Operations: 10 1) Selection or Restriction Operation: -
  • 11.
  • 12.
  • 14.
  • 15. 15
  • 16. 16 1) Union Operation: - 2. Set Operations:
  • 17.
  • 18. 18
  • 19. 19 2) Set Difference Operation: -
  • 20.
  • 21. 21
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27 4) Cartesian Product Operation: -
  • 28.
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32 1) Theta/Equi Join Operation: - 3. Join Operations:
  • 33. 33
  • 34. 34 2) Natural Join Operation: -
  • 35. 35
  • 36. 36
  • 37. 37 3) Left Outer Join Operation: -
  • 38. 38
  • 39. 39
  • 40. 40 4) Semi Join Operation: -
  • 41. 41
  • 42. 42
  • 43. 4. Division Operations: 43 1) Division Operation: -
  • 44. 44
  • 45. 45
  • 46. 5. Aggregate & Grouping Operations: 46 1) Aggregate Operation: -
  • 47. 47
  • 48. 48
  • 50. 50
  • 51. 51
  • 52. 52
  • 54. Relational Calculus  In the relational calculus, there is no description of how to evaluate a query; a relational calculus query specifies what is to be retrieved rather than how to retrieve it.  The relational calculus is not related to differential and integral calculus in mathematics, but takes its name from a branch of symbolic logic called predicate calculus. When applied to databases, it is found in two forms: tuple relational calculus, as originally proposed by Codd (1972), and domain relational calculus, as proposed by Lacroix and Pirotte (1977). 54
  • 55.  In first-order logic or predicate calculus, a predicate is a truth- valued function with arguments. When we substitute values for the arguments, the function yields an expression, called a proposition, which can be either true or false. For example, the sentences, ‘John White is a member of staff’ and ‘John White earns more than Ann Beech’ are both propositions, since we can determine whether they are true or false. In the first case, we have a function, ‘is a member of staff’, with one argument (John White); in the second case, we have a function, ‘earns more than’, with two arguments (John White and Ann Beech). 55 Continued…
  • 56.  If a predicate contains a variable, as in ‘x is a member of staff’, there must be an associated rangefor x. When we substitute some values of this range for x, the proposition may be true; for other values, it may be false. For example, if the range is the set of all people and we replace x by John White, the proposition ‘John White is a member of staff’ is true. If we replace x by the name of a person who is not a member of staff, the proposition is false. 56 Continued…
  • 57.  If P is a Predicate/Condition, then we can write the set of all x such that P is true for x, as: {x | P(x)}  We may connect predicates by the logical connectives: ∧ (AND), ∨ (OR), and ~ (NOT) to form compound predicates 57 Continued…
  • 58.  In the tuple relational calculus we are interested in finding tuples for which a predicate is true. The calculus is based on the use of tuple variables. A tuple variable is a variable that ‘ranges over’ a named relation: that is, a variable whose only allowable values are tuples of the relation. For example, to specify the range of a tuple variable S as the Staff relation, we write: Staff(S)  To express the query ‘Find the set of all tuples S such that F(S) is true’, we can write: {S | F(S)} 58 Tuple Relational Calculus
  • 59.  F is called a formula (well-formed formula). For example, to express the query ‘Find the staffNo, fName, lName, position, DOB, salary, and branchNo of all staff earning more than £10,000’, we can write: {S | Staff(S) ∧ S.salary > 10000}  S.salary means the value of the salary attribute for the tuple variable S. To retrieve a particular attribute, such as salary, we would write: {S.salary | Staff(S) ∧ S.salary > 10000} 59 Continued…
  • 60.  There are two quantifiers we can use with formulae to tell how many instances the predicate applies to. The existential quantifier ∃ (‘there exists’) is used in formulae that must be true for at least one instance, such as: Staff(S) ∧ (∃B) (Branch(B) ∧ (B.branchNo = S.branchNo) ∧ B.city = ‘London’) This means, ‘There exists a Branch tuple that has the same branchNo as the branchNo of the current Staff tuple, S, and is located in London’.  The universal quantifier ∀ (‘for all’) is used in statements about every instance, such as: (∀B) (B.city ≠ ‘Paris’) This means, ‘For all Branch tuples, the address is not in Paris’. 60 The Existential and Universal Quantifiers
  • 61.  Tuple variables that are qualified by ∀ or ∃ are called bound variables, otherwise the tuple variables are called free variables. The only free variables in a relational calculus expression should be those on the left side of the bar ( | ). For example, in the following query: {S.fName, S.lName | Staff(S) ∧ (∃B) (Branch(B) ∧ (B.branchNo = S.branchNo) ∧ B.city = ‘London’)}  S is the only free variable and S is then bound successively to each tuple of Staff. 61 Continued…
  • 62. 62
  • 63.
  • 65. 65
  • 66. 66
  • 67. 67
  • 69. Recommended Readings Chapter 4 from: -  Database Systems-A Practical Approach to Design, Implementation and Management by Thomas Connolly and Carolyn BEGG, 4th Edition (Page No. 139-162) 69
  • 70. Summary of Lecture 70 Lecture 5➦  Relational Algebra 1. Unary Operations: 1) Selection Operation 2) Projection Operation 2. Set Operations: 1) Union Operation 2) Set Difference Operation 3) Intersection Operation 4) Cartesian Product Operation
  • 71. Summary of Lecture 71 Lecture 5➦ 3. Join Operations: 1) Theta/Equi Join Operation 2) Natural Join Operation 3) Left Outer Join Operation 4) Semi Join Operation 4. Division Operations: 1) Division Operation 5. Aggregate & Grouping Operations: 1) Aggregate Operation 2) Grouping Operation
  • 72. Summary of Lecture 72 Lecture 5➦  Relational Calculus 1. The Existential and Universal Quantifiers 2. Tuple Relational Calculus 3. Domain Relational Calculus
  • 73.  END OF LECTURE 5 73