SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Relational Databases
Relational Algebra (1)
Select, project , set
Theories
Originally Prepared by Jennifer Widom
What is an “Algebra”?
Mathematical system consisting of:
 Operands --- variables or values from which new values can
be constructed.
 Operators --- symbols denoting procedures that construct
new values from given values.
In R1 x R2,
R1 and R2 are the operands while x is the operator . The
operator is applied on operands and new value is
constructed.
Relational Algebra(1970)
• It is the base of SQL
• It is procedural and formal query language .
– What to do and how to do .
• It is the collection of math-e metical expression . Not
implemented anywhere .
• It's an algebra that forms the underpinnings of
implemented languages like SQL.
6
Relational Algebra Operations
Relational Algebra (1)
Examples: simple University admissions database
University(uName,city,enr)
Student(sID,sName,GPA,HS)
Apply(sID,uName,major,dec)
uName city enr sID sName GPA HS sID uName major dec
University Student Apply
Simplest query: relation name
uName city enr sID sName GPA HS sID uName major dec
University Student Apply
Relational Algebra (1)
Student
we'll get as a result a copy of the student relation
We will further use operators to filter, slice, combine
9
Selection (or Restriction)
• predicate (R)
– Works on a single relation R and defines
a relation that contains only those tuples
(rows) of R that satisfy the specified
condition (predicate).
15
Example - Selection (or Restriction)
• List all staff with a salary greater
than £10,000.
salary > 10000 (Staff)
Solution
• List all staff with a salary greater than
£10,000.
• salary > 10000 (Staff)
Select operator (σcondition R): picks certain rows
Students with GPA>3.7
σ GPA>3.7 (Students)
Student
Relational Algebra (1)
sID sName GPA HS
1 Ahmed 3.4 1200
2 Ali 3.75 2000
sID sName GPA HS
2 Ali 3.75 2000
Select operator (σcondition R): picks certain rows
Students with GPA>3.7 and HS<1000
σ GPA>3.7 ^ HS<1000 (Students)
Applications to Comsats with CS as major
σ major=‘CS’ ^ uName = ‘Comsats’ (Apply)
uName city enr sID sName GPA HS sID uName major dec
University Student Apply
Relational Algebra (1)
19
Projection
• col1, . . . , coln(R)
– Works on a single relation R and defines a
relation that contains a vertical subset of R,
extracting the values of specified attributes
and eliminating duplicates.
22
Example - Projection
• Produce a list of salaries for all staff, showing
only staffNo, salary details.
staffNo, salary(Staff)
Example (student)
Roll no Name Age
1 sara 19
2 Ali 20
3 ahad 18
Answers
• Retrieve the roll no from table
– 𝜋 𝑟𝑜𝑙𝑙 𝑛𝑜 𝑠𝑡𝑢𝑑𝑒𝑛𝑡
• Retrieve the Name of student whose roll no is
2
– 𝜋 name (𝜎 𝑟𝑜𝑙𝑙 𝑛𝑜 = 2(𝑆𝑡𝑢𝑑𝑒𝑛𝑡 ))
Project operator (∏A1,A2,A3,…An R): picks certain columns
ID and major of all applications
∏sID,major (Apply)
Relational Algebra (1)
sID uName major dec
1 Comsats CS No
1 Comsats EE Yes
2 NUST CS No
Apply
sID major
1 CS
1 EE
2 CS
To pick both rows and columns…
ID and name of students with GPA>3.7
∏sID,sName ( σ GPA>3.7 (Students) )
Relational Algebra (1)
sID sName GPA HS
1 Ahmed 3.4 1200
2 Ali 3.75 2000
Student
sID sName
2 Ali
Duplicates
List of application’s majors and decisions
∏major,dec (Apply)
The semantics of relational algebra says that duplicates are always eliminated. So if you
run a query that would logically have a lot of duplicate values, you just get one value for
each result.
Relational Algebra (1)
sID uName major dec
1 Comsats CS No
1 Comsats EE Yes
2 NUST CS No
Apply
major dec
CS No
EE Yes
30
Union
• R  S
– Union of two relations R and S defines a relation that
contains all the tuples of R, or S, or both R and S, duplicate
tuples being eliminated.
– R and S must be union-compatible.
• If R and S have I and J tuples, respectively, union is
obtained by concatenating them into one relation with
a maximum of (I + J) tuples.
31
Example - Union
• List all cities where there is either
a branch office or a property for
rent.
city(Branch) 
city(PropertyForRent)
32
Intersection
• R  S
– Defines a relation consisting of the set
of all tuples that are in both R and S.
– R and S must be union-compatible.
• Expressed using basic operations:
R  S = R – (R – S)
33
Example - Intersection
• List all cities where there is both
a branch office and at least one
property for rent.
city(Branch) 
city(PropertyForRent)
35
Set Difference
• R – S
– Defines a relation consisting of the
tuples that are in relation R, but
not in S.
– R and S must be union-compatible.
Example
• Find the name of a person who is a student
but not instructor
• 𝜋 𝑛𝑎𝑚𝑒 (𝑠𝑡𝑢𝑑𝑒𝑛𝑡 )-𝜋 𝑛𝑎𝑚𝑒 (𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑜𝑟 )
39
Cartesian product
• R X S
– Defines a relation that is the
concatenation of every tuple of
relation R with every tuple of
relation S.
Cross-product (X): combine two relations
( Cartesian product)
X =
Student.sID sName GPA HS Apply.sID uName major dec
1 Ahmed 3.4 1200 1 Comsats CS No
1 Ahmed 3.4 1200 1 Comsats EE Yes
1 Ahmed 3.4 1200 2 NUST CS No
2 Ali 3.75 2000 1 Comsats CS No
2 Ali 3.75 2000 1 Comsats EE Yes
2 Ali 3.75 2000 2 NUST CS No
sID sName GPA HS
1 Ahmed 3.4 1200
2 Ali 3.75 2000
sID uName major dec
1 Comsats CS No
1 Comsats EE Yes
2 NUST CS No
Student Apply
Relational Algebra (1)
Cross-product (X): combine two relations
(Cartesian product)
Names and GPAs of students with HS>1000 who applied to CS
and were rejected
∏sName,GPA ( σ Student.sID=Apply.sID ^ HS>1000 ^ major=‘CS’ ^ dec=‘No’ (Students x Apply))
uName city enr sID sName GPA HS sID uName major dec
University Student Apply
Relational Algebra (1)
Relational Algebra (1)
Query (expression) on set of relations produces
relation as a result
 Simplest query: relation name
 Use operators to filter, slice, combine
 Operators so far: select, project, cross-product,
natural join, theta join , rename operators
Names and GPAs of students with HS>1000
who applied to CS
and were rejected

Weitere ähnliche Inhalte

Was ist angesagt?

Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra pptGirdharRatne
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusemailharmeet
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data StructureKeno benti
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational CalculusKunal Anand
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingSam Light
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & CalculusAbdullah Khosa
 

Was ist angesagt? (20)

Trees
Trees Trees
Trees
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Binary codes
Binary codesBinary codes
Binary codes
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational Calculus
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Ch5a
Ch5aCh5a
Ch5a
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
 

Ähnlich wie Lecture-3 Relational Algebra I.pptx

Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculusSalman Vadsarya
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Raj vardhan
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATELShashi Patel
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdfKavinilaa
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operationsSanthiNivas
 
Relational Algebra.ppt
Relational Algebra.pptRelational Algebra.ppt
Relational Algebra.pptSreenivas R
 
3 relational model
3 relational model3 relational model
3 relational modelUtkarsh De
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbmsshekhar1991
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 

Ähnlich wie Lecture-3 Relational Algebra I.pptx (20)

R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
Ra Revision
Ra RevisionRa Revision
Ra Revision
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
07.04 joins
07.04 joins07.04 joins
07.04 joins
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculus
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
354 ch6
354 ch6354 ch6
354 ch6
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
Relational Algebra.ppt
Relational Algebra.pptRelational Algebra.ppt
Relational Algebra.ppt
 
3 relational model
3 relational model3 relational model
3 relational model
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Algebra
AlgebraAlgebra
Algebra
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 

Mehr von HanzlaNaveed1

Lecture 25 Link Layer - Error detection and Multiple Access.pptx
Lecture 25 Link Layer - Error detection and Multiple Access.pptxLecture 25 Link Layer - Error detection and Multiple Access.pptx
Lecture 25 Link Layer - Error detection and Multiple Access.pptxHanzlaNaveed1
 
Lecture 23 DHCP and NAT.pptx
Lecture 23 DHCP and NAT.pptxLecture 23 DHCP and NAT.pptx
Lecture 23 DHCP and NAT.pptxHanzlaNaveed1
 
Lecture 22 What inside the Router.pptx
Lecture 22 What inside the Router.pptxLecture 22 What inside the Router.pptx
Lecture 22 What inside the Router.pptxHanzlaNaveed1
 
Lecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxLecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxHanzlaNaveed1
 
Lecture 06 and 07.pptx
Lecture 06 and 07.pptxLecture 06 and 07.pptx
Lecture 06 and 07.pptxHanzlaNaveed1
 
Lecture 26 Link Layer .pptx
Lecture 26 Link Layer .pptxLecture 26 Link Layer .pptx
Lecture 26 Link Layer .pptxHanzlaNaveed1
 
Lecture 19 and 20 IP Addressing.pptx
Lecture 19 and 20 IP Addressing.pptxLecture 19 and 20 IP Addressing.pptx
Lecture 19 and 20 IP Addressing.pptxHanzlaNaveed1
 
Lecture 05 OSI Model and IP Protocol Suite.ppt
Lecture 05 OSI Model and IP Protocol Suite.pptLecture 05 OSI Model and IP Protocol Suite.ppt
Lecture 05 OSI Model and IP Protocol Suite.pptHanzlaNaveed1
 

Mehr von HanzlaNaveed1 (8)

Lecture 25 Link Layer - Error detection and Multiple Access.pptx
Lecture 25 Link Layer - Error detection and Multiple Access.pptxLecture 25 Link Layer - Error detection and Multiple Access.pptx
Lecture 25 Link Layer - Error detection and Multiple Access.pptx
 
Lecture 23 DHCP and NAT.pptx
Lecture 23 DHCP and NAT.pptxLecture 23 DHCP and NAT.pptx
Lecture 23 DHCP and NAT.pptx
 
Lecture 22 What inside the Router.pptx
Lecture 22 What inside the Router.pptxLecture 22 What inside the Router.pptx
Lecture 22 What inside the Router.pptx
 
Lecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxLecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptx
 
Lecture 06 and 07.pptx
Lecture 06 and 07.pptxLecture 06 and 07.pptx
Lecture 06 and 07.pptx
 
Lecture 26 Link Layer .pptx
Lecture 26 Link Layer .pptxLecture 26 Link Layer .pptx
Lecture 26 Link Layer .pptx
 
Lecture 19 and 20 IP Addressing.pptx
Lecture 19 and 20 IP Addressing.pptxLecture 19 and 20 IP Addressing.pptx
Lecture 19 and 20 IP Addressing.pptx
 
Lecture 05 OSI Model and IP Protocol Suite.ppt
Lecture 05 OSI Model and IP Protocol Suite.pptLecture 05 OSI Model and IP Protocol Suite.ppt
Lecture 05 OSI Model and IP Protocol Suite.ppt
 

Kürzlich hochgeladen

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Kürzlich hochgeladen (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

Lecture-3 Relational Algebra I.pptx

  • 1. Relational Databases Relational Algebra (1) Select, project , set Theories Originally Prepared by Jennifer Widom
  • 2. What is an “Algebra”? Mathematical system consisting of:  Operands --- variables or values from which new values can be constructed.  Operators --- symbols denoting procedures that construct new values from given values. In R1 x R2, R1 and R2 are the operands while x is the operator . The operator is applied on operands and new value is constructed.
  • 3. Relational Algebra(1970) • It is the base of SQL • It is procedural and formal query language . – What to do and how to do . • It is the collection of math-e metical expression . Not implemented anywhere . • It's an algebra that forms the underpinnings of implemented languages like SQL.
  • 4.
  • 5.
  • 7. Relational Algebra (1) Examples: simple University admissions database University(uName,city,enr) Student(sID,sName,GPA,HS) Apply(sID,uName,major,dec) uName city enr sID sName GPA HS sID uName major dec University Student Apply
  • 8. Simplest query: relation name uName city enr sID sName GPA HS sID uName major dec University Student Apply Relational Algebra (1) Student we'll get as a result a copy of the student relation We will further use operators to filter, slice, combine
  • 9. 9 Selection (or Restriction) • predicate (R) – Works on a single relation R and defines a relation that contains only those tuples (rows) of R that satisfy the specified condition (predicate).
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. 15 Example - Selection (or Restriction) • List all staff with a salary greater than £10,000. salary > 10000 (Staff)
  • 16. Solution • List all staff with a salary greater than £10,000. • salary > 10000 (Staff)
  • 17. Select operator (σcondition R): picks certain rows Students with GPA>3.7 σ GPA>3.7 (Students) Student Relational Algebra (1) sID sName GPA HS 1 Ahmed 3.4 1200 2 Ali 3.75 2000 sID sName GPA HS 2 Ali 3.75 2000
  • 18. Select operator (σcondition R): picks certain rows Students with GPA>3.7 and HS<1000 σ GPA>3.7 ^ HS<1000 (Students) Applications to Comsats with CS as major σ major=‘CS’ ^ uName = ‘Comsats’ (Apply) uName city enr sID sName GPA HS sID uName major dec University Student Apply Relational Algebra (1)
  • 19. 19 Projection • col1, . . . , coln(R) – Works on a single relation R and defines a relation that contains a vertical subset of R, extracting the values of specified attributes and eliminating duplicates.
  • 20.
  • 21.
  • 22. 22 Example - Projection • Produce a list of salaries for all staff, showing only staffNo, salary details. staffNo, salary(Staff)
  • 23. Example (student) Roll no Name Age 1 sara 19 2 Ali 20 3 ahad 18
  • 24. Answers • Retrieve the roll no from table – 𝜋 𝑟𝑜𝑙𝑙 𝑛𝑜 𝑠𝑡𝑢𝑑𝑒𝑛𝑡 • Retrieve the Name of student whose roll no is 2 – 𝜋 name (𝜎 𝑟𝑜𝑙𝑙 𝑛𝑜 = 2(𝑆𝑡𝑢𝑑𝑒𝑛𝑡 ))
  • 25. Project operator (∏A1,A2,A3,…An R): picks certain columns ID and major of all applications ∏sID,major (Apply) Relational Algebra (1) sID uName major dec 1 Comsats CS No 1 Comsats EE Yes 2 NUST CS No Apply sID major 1 CS 1 EE 2 CS
  • 26. To pick both rows and columns… ID and name of students with GPA>3.7 ∏sID,sName ( σ GPA>3.7 (Students) ) Relational Algebra (1) sID sName GPA HS 1 Ahmed 3.4 1200 2 Ali 3.75 2000 Student sID sName 2 Ali
  • 27. Duplicates List of application’s majors and decisions ∏major,dec (Apply) The semantics of relational algebra says that duplicates are always eliminated. So if you run a query that would logically have a lot of duplicate values, you just get one value for each result. Relational Algebra (1) sID uName major dec 1 Comsats CS No 1 Comsats EE Yes 2 NUST CS No Apply major dec CS No EE Yes
  • 28.
  • 29.
  • 30. 30 Union • R  S – Union of two relations R and S defines a relation that contains all the tuples of R, or S, or both R and S, duplicate tuples being eliminated. – R and S must be union-compatible. • If R and S have I and J tuples, respectively, union is obtained by concatenating them into one relation with a maximum of (I + J) tuples.
  • 31. 31 Example - Union • List all cities where there is either a branch office or a property for rent. city(Branch)  city(PropertyForRent)
  • 32. 32 Intersection • R  S – Defines a relation consisting of the set of all tuples that are in both R and S. – R and S must be union-compatible. • Expressed using basic operations: R  S = R – (R – S)
  • 33. 33 Example - Intersection • List all cities where there is both a branch office and at least one property for rent. city(Branch)  city(PropertyForRent)
  • 34.
  • 35. 35 Set Difference • R – S – Defines a relation consisting of the tuples that are in relation R, but not in S. – R and S must be union-compatible.
  • 36.
  • 37.
  • 38. Example • Find the name of a person who is a student but not instructor • 𝜋 𝑛𝑎𝑚𝑒 (𝑠𝑡𝑢𝑑𝑒𝑛𝑡 )-𝜋 𝑛𝑎𝑚𝑒 (𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑜𝑟 )
  • 39. 39 Cartesian product • R X S – Defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S.
  • 40.
  • 41. Cross-product (X): combine two relations ( Cartesian product) X = Student.sID sName GPA HS Apply.sID uName major dec 1 Ahmed 3.4 1200 1 Comsats CS No 1 Ahmed 3.4 1200 1 Comsats EE Yes 1 Ahmed 3.4 1200 2 NUST CS No 2 Ali 3.75 2000 1 Comsats CS No 2 Ali 3.75 2000 1 Comsats EE Yes 2 Ali 3.75 2000 2 NUST CS No sID sName GPA HS 1 Ahmed 3.4 1200 2 Ali 3.75 2000 sID uName major dec 1 Comsats CS No 1 Comsats EE Yes 2 NUST CS No Student Apply Relational Algebra (1)
  • 42. Cross-product (X): combine two relations (Cartesian product) Names and GPAs of students with HS>1000 who applied to CS and were rejected ∏sName,GPA ( σ Student.sID=Apply.sID ^ HS>1000 ^ major=‘CS’ ^ dec=‘No’ (Students x Apply)) uName city enr sID sName GPA HS sID uName major dec University Student Apply Relational Algebra (1)
  • 43. Relational Algebra (1) Query (expression) on set of relations produces relation as a result  Simplest query: relation name  Use operators to filter, slice, combine  Operators so far: select, project, cross-product, natural join, theta join , rename operators
  • 44. Names and GPAs of students with HS>1000 who applied to CS and were rejected

Hinweis der Redaktion

  1. For the examples in this lecture we're going to be using a simple University admission relations database with three relations. The first relation, the University relation, contains information about the University name, city, and enrollment of the University. The second relation, the student relation, contains an ID for each student, the student's name, GPA and the size of the high school they attended. And, finally, the third relation contains information about students applying to Universities. Specifically, the student's ID, the University name where they're applying, the major they're applying for and the decision of that application. I've underlined the keys for these three relations. As a reminder, a key is an attribute or a set of attributes whose value is guaranteed to be unique. So, for example, we're going to assume the University names are unique, student IDs are unique and that students will only apply to each University for a particular major one time.
  2. The simplest query in relational algebra is a query that is simply the name of a relation. So, for example, we can write a query, "student" and that's a valid expression in relational algebra. If we run that query on our database we'll get as a result a copy of the student relation. Now what happens next is that we're going to use operators of the relational algebra to filter relations, slice relations, and combine relations.
  3. So, the select operator is used to pick certain rows out of a relation. The select operator is denoted by a small Sigma with a subscript--that's the condition that's used to filter the rows that we extract from the relations.
  4. So, the select operator is used to pick certain rows out of a relation. The select operator is denoted by a small Sigma with a subscript--that's the condition that's used to filter the rows that we extract from the relations.
  5. Our next operator is the Project Operator. So the select operator picks certain rows, and the project operator picks certain columns. So let's say we're interested in the applications, but all we wanted to know was the list of ID's and the decisions for those applications. The project operator is written using the Greek pi symbol, and now the subscript is a list of the column names that we would like to extract.
  6. Now, what if we're interested in picking both rows and columns at the same time. So we want only some of the rows, and we want only some of the columns. Now we're going to compose operators. Remember that relational queries produce relations . So we can write a query, say, with the select operator of the students whose GPA is greater than 3.7. And now, we can take that whole expression which produces a relation, and we can apply the project operator to that, and we can get out the student ID and the student name. And we can compose these as much as we want. We can have select over project, over select, select, project, and so on.
  7. Now let's talk about duplicate values in the results of relational algebra queries. Let's suppose we ask for a list of the majors that people have applied for and the decision for those majors. So we write that as the project of the major and the decision on the applied relation. You might think that when we get the results of this query, we're going to have a lot of duplicate values. You can imagine in a large realistic database of applications, there's going to be hundreds of people applying for majors and having a yes or a no decision. The semantics of relational algebra says that duplicates are always eliminated. So if you run a query that would logically have a lot of duplicate values, you just get one value for each result. That's actually a bit of a difference with the SQL language. So, SQL is based on what's known as multi-sets or bags and that means that we don't eliminate duplicates, whereas relational algebra is based on sets themselves and duplicates are eliminated. There is a multi-set or bad relational algebra defined as well but we'll be fine by just considering the set relational algebra in this course.
  8. Our first operator that combines two relations is the cross-product operator, also known as the Cartesian product. What this operator does, is it takes two relations and kinda glues them together so that their schema of the result is the combination of the schemas of the two relations and the contents of the result are every combination of tuples from those relations. So let's talk about, say, doing the cross products of students and apply. So if we do the cross product we'll get at the result a big relation, here, which is going to have eight attributes. The eight attributes across the student and apply now the only small little trick is that when we glue two relations together sometimes they'll have the same attribute and we can see we have SID on both sides. So just as a notational convention, when cross-product is done and there's two attributes that are named, they're prefaced with the name of the relation they came from. So this one would be referred to in the cross-product as the Student.SID where the other would be referred to as the Apply.SID.. Now let's talk about the contents of these. So let's suppose that the student relation had S-tuples in it and that's how many tuples, while the apply had A tuples in it, the result of the Cartesian products is gonna have S times A tuples, is going to have one tuple for every combination of tuples from the student relation and the apply relation. Now, the cross-product seems like it might not be that helpful, but what is interesting is when we use the cross-product together with other operators.
  9. And let's see a big example of that. Let's suppose that we want to get the names and GPAs of students with a high school size greater than a thousand who applied to CS and were rejected. Okay, so let's take a look. We're going to have to access the students and the apply records in order to run this query. So what we'll do is we'll take student cross apply as our starting point. So now we have a big relation that contains eight attributes and all of those tuples that we described previously. But now we're going to start making things more interesting, because what we're going to do is a big selection over this relation. And that selection is first of all going to make sure that it only combines student and apply tuples that are referring to the same student. So to do that, we write student dot SID equals apply dot SID. So now we've filtered the result of that cross-product to only include combinations of student and apply by couples that make sets. Now we have to do a little bit of additional filtering. We said that we want the high school size to be greater than a thousand, so we do an "and" operator in the high school. We want them to have applied to CS so that's and major equals CS. We're getting a nice big query here. And finally we want them to have been rejected, so "and decision" equals, we'll just be using No for reject. So now, we've got that gigantic query. But that gets us exactly what we want except for one more thing, which is, as I said, all we want is their names and GPAs. So finally we take a big parentheses around here and we apply to that the projection operator, getting the student name and the GPA. And that is the relational algebra expression that produces the query that we have written in English.
  10. So, in conclusion, relational algebra is a formal language. It operates on sets of relations and produces relations as a result. The simplest query is just the name of a relation and then operators are used to filter relations, slice them, and combine them. So far, we've learned the select operator for selecting rows; the project operator for selecting columns; the cross-product operator for combining every possible pair of tuples from two relations; and then two abbreviations, the natural join, which a very useful way to combine relations by enforcing a equality on certain columns; and the theta join operator.