SlideShare a Scribd company logo
Chapter 4 Relational Algebra  Pearson Education © 2009
Chapter 5 - Objectives Meaning of the term relational completeness. How to form queries in relational algebra. How to form queries in tuple relational calculus. How to form queries in domain relational calculus. Categories of relational DML. Pearson Education © 2009
Introduction Relational algebra and relational calculus are formal languages associated with the relational model. Informally, relational algebra is a (high-level) procedural language and relational calculus a non-procedural language. However, formally both are equivalent to one another. A language that produces a relation that can be derived using relational calculus is  relationally complete . Pearson Education © 2009
Relational Algebra Relational algebra operations work on one or more relations to define another relation without changing the original relations. Both operands and results are relations, so output from one operation can become input to another operation.  Allows expressions to be nested, just as in arithmetic. This property is called  closure . Pearson Education © 2009
Relational Algebra Five basic operations in relational algebra: Selection, Projection, Cartesian product, Union,  and Set Difference.  These perform most of the data retrieval operations needed. Also have Join, Intersection, and Division operations, which can be expressed in terms of 5 basic operations. Pearson Education © 2009
Relational Algebra Operations Pearson Education © 2009
Relational Algebra Operations Pearson Education © 2009
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 ). Pearson Education © 2009
Example - Selection (or Restriction) List all staff with a salary greater than £10,000.  salary > 10000  (Staff) Pearson Education © 2009
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. Pearson Education © 2009
Example - Projection Produce a list of salaries for all staff, showing only  staffNo, fName, lName, and salary details.  staffNo, fName, lName, salary (Staff) Pearson Education © 2009
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. Pearson Education © 2009
Example - Union List all cities where there is either a branch office or a property for rent.  city (Branch)      city (PropertyForRent) Pearson Education © 2009
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. Pearson Education © 2009
Example - Set Difference List all cities where there is a branch office but no properties for rent.  city (Branch) –   city (PropertyForRent) Pearson Education © 2009
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) Pearson Education © 2009
Example - Intersection List all cities where there is both a branch office and at least one property for rent.  city (Branch)      city (PropertyForRent) Pearson Education © 2009
Cartesian product R X S Defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S. Pearson Education © 2009
Example - Cartesian product List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) X (  clientNo, propertyNo, comment  (Viewing)) Pearson Education © 2009
Cartesian Product
Example - Cartesian product and Selection Use selection operation to extract those tuples where Client.clientNo = Viewing.clientNo.  Client . clientN o =  V iewing. clientN o ((  clientNo ,   f N ame,   l N ame ( Client ))    (  clientN o,   p ropertyN o,   comment (Viewing))) Cartesian product and Selection can be reduced to a single operation called a  Join . Pearson Education © 2009
Join Operations Join is a derivative of Cartesian product. Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations.  One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems. Pearson Education © 2009
Join Operations Various forms of join operation Theta join Equijoin (a particular type of Theta join) Natural join Outer join Semijoin Pearson Education © 2009
Theta join (  -join) R  F S Defines a relation that contains tuples satisfying the predicate F from the Cartesian product of R and S.  The predicate F is of the form R.a i     S.b i  where    may be one of the comparison operators (<,   , >,   , =,   ). Pearson Education © 2009
Theta join (  -join) Can rewrite Theta join using basic Selection and Cartesian product operations. R  F S =   F (R    S) Degree of a Theta join is sum of degrees of the operand relations R and S. If predicate F contains only equality (=), the term  Equijoin  is used.  Pearson Education © 2009
Example - Equijoin  List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client))  Client.clientNo = Viewing.clientNo  (  clientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
Natural join R  S An Equijoin of the two relations R and S over all common attributes  x . One occurrence of each common attribute is eliminated from the result. Hence the degree is the sum of the degrees of the relations R and S less the number of attributes in  x   Pearson Education © 2009
Example - Natural join List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client))  (  clientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
Outer join To display rows in the result that do not have matching values in the join column, use Outer join. R  S (Left) outer join is join in which tuples from R that do not have matching values in common columns of S are also included in result relation. Pearson Education © 2009
Example - Left Outer join Produce a status report on property viewings.  propertyNo, street, city (PropertyForRent)  Viewing Pearson Education © 2009
Semijoin R  F  S Defines a relation that contains the tuples of R that participate in the join of R with S. Can rewrite Semijoin using Projection and Join: R  F  S  =   A (R  F  S) Pearson Education © 2009
Example - Semijoin List complete details of all staff who work at the branch in Glasgow. Staff  Staff.branchNo=Branch.branchNo (  city=‘Glasgow’ (Branch)) Pearson Education © 2009
Division R    S Defines a relation over the attributes C that consists of set of tuples from R that match combination of  every  tuple in S. Expressed using basic operations: T 1       C (R) T 2       C ((S X T 1 ) – R) T    T 1  – T 2 Pearson Education © 2009
Example - Division Identify all clients who have viewed all properties with three rooms. (  clientNo, propertyNo (Viewing))     (  propertyNo (  rooms = 3  (PropertyForRent))) Pearson Education © 2009
Aggregate Operations  AL (R)   Applies aggregate function list, AL, to R to define a relation over the aggregate list.  AL contains one or more (<aggregate_function>, <attribute>) pairs   . Main aggregate functions are: COUNT, SUM, AVG, MIN, and MAX. Pearson Education © 2009
Example – Aggregate Operations How many properties cost more than £350 per month to rent?  R (myCount)   COUNT   propertyNo  ( σ rent > 350  (PropertyForRent))   Pearson Education © 2009
Grouping Operation GA  AL (R)   Groups tuples of R by grouping attributes, GA, and then applies aggregate function list, AL, to define a new relation.  AL contains one or more (<aggregate_function>, <attribute>) pairs.  Resulting relation contains the grouping attributes, GA, along with results of each of the aggregate functions . Pearson Education © 2009
Example – Grouping Operation Find the number of staff working in each branch and the sum of their salaries.  R (branchNo, myCount, mySum) branchNo     COUNT staffNo,   SUM salary  (Staff)   Pearson Education © 2009
Ad

More Related Content

What's hot (20)

Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculus
Salman Vadsarya
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
shekhar1991
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
WebStackAcademy
 
Database Design
Database DesignDatabase Design
Database Design
learnt
 
Functional dependencies in Database Management System
Functional dependencies in Database Management SystemFunctional dependencies in Database Management System
Functional dependencies in Database Management System
Kevin Jadiya
 
ER Diagram
ER DiagramER Diagram
ER Diagram
Robby Firmansyah
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
VENNILAV6
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data mining
kavitha muneeshwaran
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
Erd practice exercises
Erd practice exercisesErd practice exercises
Erd practice exercises
Jennifer Polack
 
Data models
Data modelsData models
Data models
Usman Tariq
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query Processing
Mythili Kannan
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Mahesh Bhalerao
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
Visakh V
 
Data modeling using the entity relationship model
Data modeling using the entity relationship modelData modeling using the entity relationship model
Data modeling using the entity relationship model
Jafar Nesargi
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 
Types of UML diagrams
Types of UML diagramsTypes of UML diagrams
Types of UML diagrams
Mukesh Tekwani
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
Arti Parab Academics
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculus
Salman Vadsarya
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
shekhar1991
 
Database Design
Database DesignDatabase Design
Database Design
learnt
 
Functional dependencies in Database Management System
Functional dependencies in Database Management SystemFunctional dependencies in Database Management System
Functional dependencies in Database Management System
Kevin Jadiya
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
VENNILAV6
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data mining
kavitha muneeshwaran
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query Processing
Mythili Kannan
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Mahesh Bhalerao
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
Visakh V
 
Data modeling using the entity relationship model
Data modeling using the entity relationship modelData modeling using the entity relationship model
Data modeling using the entity relationship model
Jafar Nesargi
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 

Viewers also liked (12)

Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashing
Jeet Poria
 
Architecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independenceArchitecture of-dbms-and-data-independence
Architecture of-dbms-and-data-independence
Anuj Modi
 
Database management system basic, database, database management, learn databa...
Database management system basic, database, database management, learn databa...Database management system basic, database, database management, learn databa...
Database management system basic, database, database management, learn databa...
University of Science and Technology Chitttagong
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
Shubham Dwivedi
 
PLM Introduction
PLM IntroductionPLM Introduction
PLM Introduction
Jayakumar Vadivelu
 
Database language
Database languageDatabase language
Database language
University of Science and Technology Chitttagong
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
Jargalsaikhan Alyeksandr
 
Trigger
TriggerTrigger
Trigger
Slideshare
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
koolkampus
 
ERP Implementation Life Cycle
ERP Implementation Life CycleERP Implementation Life Cycle
ERP Implementation Life Cycle
Apurv Gourav
 
DBMS - Normalization
DBMS - NormalizationDBMS - Normalization
DBMS - Normalization
Jitendra Tomar
 
Business process reengineering
Business process reengineeringBusiness process reengineering
Business process reengineering
Neelkamal Sharma
 
Ad

Similar to Relational Algebra-Database Systems (20)

Relational algebra dbms (2130703) - 160920107003
Relational algebra  dbms (2130703) - 160920107003Relational algebra  dbms (2130703) - 160920107003
Relational algebra dbms (2130703) - 160920107003
Prashant odhavani
 
Mathematics_College_Entrance_Exam_Reviewer
Mathematics_College_Entrance_Exam_ReviewerMathematics_College_Entrance_Exam_Reviewer
Mathematics_College_Entrance_Exam_Reviewer
deplkeo002
 
MAT1033.4.5.ppt
MAT1033.4.5.pptMAT1033.4.5.ppt
MAT1033.4.5.ppt
StreetFoodairy
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
SanthiNivas
 
Relational Algebra.pptx for Module four
Relational Algebra.pptx for  Module fourRelational Algebra.pptx for  Module four
Relational Algebra.pptx for Module four
Monaliaghosh
 
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTUrelational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
KusumaS36
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
Roshni814224
 
Database management system chapter eigei
Database management system chapter eigeiDatabase management system chapter eigei
Database management system chapter eigei
cscmalligawad
 
Chapter 08.pptx
Chapter 08.pptxChapter 08.pptx
Chapter 08.pptx
EliasPetros
 
Chapter6
Chapter6Chapter6
Chapter6
Reham Maher El-Safarini
 
Relational-algebra in Data base management ppts
Relational-algebra in Data base management pptsRelational-algebra in Data base management ppts
Relational-algebra in Data base management ppts
sandeep945342
 
Module 2-2.ppt
Module 2-2.pptModule 2-2.ppt
Module 2-2.ppt
Shylaja40
 
Relation Algebra
Relation AlgebraRelation Algebra
Relation Algebra
A. S. M. Shafi
 
relation algebra unit ii notes and their queries
relation algebra unit ii notes and their queriesrelation algebra unit ii notes and their queries
relation algebra unit ii notes and their queries
farhana538800
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculus
Kumar
 
L8 design1
L8 design1L8 design1
L8 design1
Tianlu Wang
 
RELATIONAL MODEL CONCEPTS.pptx with good explanation
RELATIONAL MODEL CONCEPTS.pptx with good explanationRELATIONAL MODEL CONCEPTS.pptx with good explanation
RELATIONAL MODEL CONCEPTS.pptx with good explanation
farsankadavandy
 
DBMS Module 2.2.pdf......................
DBMS Module 2.2.pdf......................DBMS Module 2.2.pdf......................
DBMS Module 2.2.pdf......................
sudeepjsgowda4120
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
Infinity Tech Solutions
 
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
 
Relational algebra dbms (2130703) - 160920107003
Relational algebra  dbms (2130703) - 160920107003Relational algebra  dbms (2130703) - 160920107003
Relational algebra dbms (2130703) - 160920107003
Prashant odhavani
 
Mathematics_College_Entrance_Exam_Reviewer
Mathematics_College_Entrance_Exam_ReviewerMathematics_College_Entrance_Exam_Reviewer
Mathematics_College_Entrance_Exam_Reviewer
deplkeo002
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
SanthiNivas
 
Relational Algebra.pptx for Module four
Relational Algebra.pptx for  Module fourRelational Algebra.pptx for  Module four
Relational Algebra.pptx for Module four
Monaliaghosh
 
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTUrelational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
relational algebra IN DATABASE MANAGEMENT SYSTEM COURSE FOR 4TH SEM VTU
KusumaS36
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
Roshni814224
 
Database management system chapter eigei
Database management system chapter eigeiDatabase management system chapter eigei
Database management system chapter eigei
cscmalligawad
 
Relational-algebra in Data base management ppts
Relational-algebra in Data base management pptsRelational-algebra in Data base management ppts
Relational-algebra in Data base management ppts
sandeep945342
 
Module 2-2.ppt
Module 2-2.pptModule 2-2.ppt
Module 2-2.ppt
Shylaja40
 
relation algebra unit ii notes and their queries
relation algebra unit ii notes and their queriesrelation algebra unit ii notes and their queries
relation algebra unit ii notes and their queries
farhana538800
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculus
Kumar
 
RELATIONAL MODEL CONCEPTS.pptx with good explanation
RELATIONAL MODEL CONCEPTS.pptx with good explanationRELATIONAL MODEL CONCEPTS.pptx with good explanation
RELATIONAL MODEL CONCEPTS.pptx with good explanation
farsankadavandy
 
DBMS Module 2.2.pdf......................
DBMS Module 2.2.pdf......................DBMS Module 2.2.pdf......................
DBMS Module 2.2.pdf......................
sudeepjsgowda4120
 
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
 
Ad

Recently uploaded (20)

2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 

Relational Algebra-Database Systems

  • 1. Chapter 4 Relational Algebra Pearson Education © 2009
  • 2. Chapter 5 - Objectives Meaning of the term relational completeness. How to form queries in relational algebra. How to form queries in tuple relational calculus. How to form queries in domain relational calculus. Categories of relational DML. Pearson Education © 2009
  • 3. Introduction Relational algebra and relational calculus are formal languages associated with the relational model. Informally, relational algebra is a (high-level) procedural language and relational calculus a non-procedural language. However, formally both are equivalent to one another. A language that produces a relation that can be derived using relational calculus is relationally complete . Pearson Education © 2009
  • 4. Relational Algebra Relational algebra operations work on one or more relations to define another relation without changing the original relations. Both operands and results are relations, so output from one operation can become input to another operation. Allows expressions to be nested, just as in arithmetic. This property is called closure . Pearson Education © 2009
  • 5. Relational Algebra Five basic operations in relational algebra: Selection, Projection, Cartesian product, Union, and Set Difference. These perform most of the data retrieval operations needed. Also have Join, Intersection, and Division operations, which can be expressed in terms of 5 basic operations. Pearson Education © 2009
  • 6. Relational Algebra Operations Pearson Education © 2009
  • 7. Relational Algebra Operations Pearson Education © 2009
  • 8. 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 ). Pearson Education © 2009
  • 9. Example - Selection (or Restriction) List all staff with a salary greater than £10,000.  salary > 10000 (Staff) Pearson Education © 2009
  • 10. 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. Pearson Education © 2009
  • 11. Example - Projection Produce a list of salaries for all staff, showing only staffNo, fName, lName, and salary details.  staffNo, fName, lName, salary (Staff) Pearson Education © 2009
  • 12. 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. Pearson Education © 2009
  • 13. Example - Union List all cities where there is either a branch office or a property for rent.  city (Branch)   city (PropertyForRent) Pearson Education © 2009
  • 14. 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. Pearson Education © 2009
  • 15. Example - Set Difference List all cities where there is a branch office but no properties for rent.  city (Branch) –  city (PropertyForRent) Pearson Education © 2009
  • 16. 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) Pearson Education © 2009
  • 17. Example - Intersection List all cities where there is both a branch office and at least one property for rent.  city (Branch)   city (PropertyForRent) Pearson Education © 2009
  • 18. Cartesian product R X S Defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S. Pearson Education © 2009
  • 19. Example - Cartesian product List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) X (  clientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
  • 21. Example - Cartesian product and Selection Use selection operation to extract those tuples where Client.clientNo = Viewing.clientNo.  Client . clientN o = V iewing. clientN o ((  clientNo , f N ame, l N ame ( Client ))  (  clientN o, p ropertyN o, comment (Viewing))) Cartesian product and Selection can be reduced to a single operation called a Join . Pearson Education © 2009
  • 22. Join Operations Join is a derivative of Cartesian product. Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations. One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems. Pearson Education © 2009
  • 23. Join Operations Various forms of join operation Theta join Equijoin (a particular type of Theta join) Natural join Outer join Semijoin Pearson Education © 2009
  • 24. Theta join (  -join) R F S Defines a relation that contains tuples satisfying the predicate F from the Cartesian product of R and S. The predicate F is of the form R.a i  S.b i where  may be one of the comparison operators (<,  , >,  , =,  ). Pearson Education © 2009
  • 25. Theta join (  -join) Can rewrite Theta join using basic Selection and Cartesian product operations. R F S =  F (R  S) Degree of a Theta join is sum of degrees of the operand relations R and S. If predicate F contains only equality (=), the term Equijoin is used. Pearson Education © 2009
  • 26. Example - Equijoin List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) Client.clientNo = Viewing.clientNo (  clientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
  • 27. Natural join R S An Equijoin of the two relations R and S over all common attributes x . One occurrence of each common attribute is eliminated from the result. Hence the degree is the sum of the degrees of the relations R and S less the number of attributes in x Pearson Education © 2009
  • 28. Example - Natural join List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) (  clientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
  • 29. Outer join To display rows in the result that do not have matching values in the join column, use Outer join. R S (Left) outer join is join in which tuples from R that do not have matching values in common columns of S are also included in result relation. Pearson Education © 2009
  • 30. Example - Left Outer join Produce a status report on property viewings.  propertyNo, street, city (PropertyForRent) Viewing Pearson Education © 2009
  • 31. Semijoin R F S Defines a relation that contains the tuples of R that participate in the join of R with S. Can rewrite Semijoin using Projection and Join: R F S =  A (R F S) Pearson Education © 2009
  • 32. Example - Semijoin List complete details of all staff who work at the branch in Glasgow. Staff Staff.branchNo=Branch.branchNo (  city=‘Glasgow’ (Branch)) Pearson Education © 2009
  • 33. Division R  S Defines a relation over the attributes C that consists of set of tuples from R that match combination of every tuple in S. Expressed using basic operations: T 1   C (R) T 2   C ((S X T 1 ) – R) T  T 1 – T 2 Pearson Education © 2009
  • 34. Example - Division Identify all clients who have viewed all properties with three rooms. (  clientNo, propertyNo (Viewing))  (  propertyNo (  rooms = 3 (PropertyForRent))) Pearson Education © 2009
  • 35. Aggregate Operations  AL (R) Applies aggregate function list, AL, to R to define a relation over the aggregate list. AL contains one or more (<aggregate_function>, <attribute>) pairs . Main aggregate functions are: COUNT, SUM, AVG, MIN, and MAX. Pearson Education © 2009
  • 36. Example – Aggregate Operations How many properties cost more than £350 per month to rent?  R (myCount)  COUNT propertyNo ( σ rent > 350 (PropertyForRent)) Pearson Education © 2009
  • 37. Grouping Operation GA  AL (R) Groups tuples of R by grouping attributes, GA, and then applies aggregate function list, AL, to define a new relation. AL contains one or more (<aggregate_function>, <attribute>) pairs. Resulting relation contains the grouping attributes, GA, along with results of each of the aggregate functions . Pearson Education © 2009
  • 38. Example – Grouping Operation Find the number of staff working in each branch and the sum of their salaries.  R (branchNo, myCount, mySum) branchNo  COUNT staffNo, SUM salary (Staff) Pearson Education © 2009