relational algebra
TRANSCRIPT
![Page 1: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/1.jpg)
The Relational Algebra
BY:
Faisal Ali BS-IV(CS)
![Page 2: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/2.jpg)
Relational Algebra:
Relational Algebra is a theoretical language with operations on one Or more relations to define another relation without changing the original Relation.
![Page 3: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/3.jpg)
Fundamental Operations Of Relations Algebra
• Selection
• Projection
• Cartesian product • Union
• Set difference
![Page 4: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/4.jpg)
Fundamental Operations Of Relations Algebra
•The selection and projection are unary operations ,Since they operate on one Relation.
•The other Relations work on pairs of relations and are therefore called binary Operations
![Page 5: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/5.jpg)
Fundamental Operations Of Relations Algebra
Selection (Restriction):
The Selection operation works on a single relation R and defines a relation that contains only those tuples of R that satisfy the specified condition ( predicate).
σ predicate(R)
e.g. : List all staff with a salary greater than £10,000.
σsalary > 10000(Staff)
![Page 6: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/6.jpg)
Fundamental Operations Of Relations Algebra
The Projection operation works on a single relation R and defines a relation that contains a vertical subset (Column) of R, extracting the values of specified attributes and eliminating duplicates.
Projection:
Πa1, . . . , an(R)e.g. : Produce a list of salaries for all staff, showing only the staffNo,
fName, lName, and salary details.
ΠstaffNo, fName, lName, salary(Staff)
![Page 7: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/7.jpg)
Fundamental Operations Of Relations Algebra
The 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.
Union
R S∪e.g. : List all cities where there is either a branch office or a property for rent.
Πcity(Branch) ∪ Πcity(PropertyForRent)
![Page 8: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/8.jpg)
The Set difference operation defines a relation consisting of the tuples that are in relation R, but not in S. R and S must be union-compatible.
Set difference
R − S
e.g. : List all cities where there is a branch office but no properties for rent.
Πcity(Branch) − Πcity(PropertyForRent)
Fundamental Operations Of Relations Algebra
![Page 9: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/9.jpg)
The Cartesian product operation defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S.
Cartesian product:
Fundamental Operations Of Relations Algebra
R × Se.g. : List the names and comments of all clients who have viewed a property for
rent.
(ΠclientNo, fName, lName(Client)) ×(ΠclientNo,propertyNo,comment(Viewing))
![Page 10: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/10.jpg)
Join Operations:
• The Join operation, which combines two relations to form a new relation, is one of the essential
operations in the relational algebra.
• Join is a derivative of Cartesian product, equivalent to performing a Selection operation, using the join predicate as the selection formula, over the Cartesian product of the two operand relations.
![Page 11: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/11.jpg)
Forms of Join Operations
• Theta Join
• Equijoin(a particular type of theta join)
• Natural join • Outer join
• Semi join
![Page 12: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/12.jpg)
Forms of Join Operations
Theta Join (Θ-Join)
The Theta join operation 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.ai q S.bi where q may be one of the comparison operators(<, ≤, >, ≥, =, ≠).
We can rewrite the Theta join in terms of the basic Selection and Cartesian product operations:
R ∞F S
R ∞F S = σF(R X S)
![Page 13: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/13.jpg)
Forms of Join Operations
Equijoin:
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.
![Page 14: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/14.jpg)
Forms of Join Operations
Natural Join:
The Natural join is 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.
![Page 15: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/15.jpg)
Forms of Join Operations
Outer Join:
• The (left) Outer join is a join in which tuples from R that do not have matching values in the common
attributesof S are also included in the result relation.Missing values in the second relation are set
to null• Right Outer join that keeps every tuple in the
right- and relation in the result. There is also a Full Outer join that keeps all tuples in both relations, padding
tuples with nulls when no matching tuples are found.
![Page 16: Relational Algebra](https://reader036.vdocument.in/reader036/viewer/2022082915/547f76bcb4af9f853c8b458e/html5/thumbnails/16.jpg)
Forms of Join Operations
Semi Join:
The Semijoin operation defines a relation that contains the tuples of R that participate in the join of R with S.