![Page 1: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/1.jpg)
Relational Algebra
![Page 2: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/2.jpg)
Basic concepts
• Domain: There are set of permitted values for every attribute, called its domain.
– Exp- Domain of roll number{10,11,23,56,78}
– Domain of branch{CSE,IT,ME,ECE}
• Tuple: Each row in a relation is called tuple.
• Relation: Collection of homogeneous tuples.
• Degree or Arity: Number of attributes in relation R.
• Cardinality: Number of tuples in relation R.
![Page 3: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/3.jpg)
• Keys:
• Compatibility of Relations: Relations R and S are said to be compatible if
– Both have same number of attributes.(same arity)
– And domain on ith attribute of R must be same as of ithattribute of relation S.
![Page 4: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/4.jpg)
Integrity Rules
• Rule 01
• Entity integrity
– If an attribute A of relation R is selected as primary key then it cannot accept null values.
![Page 5: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/5.jpg)
• Rule 02
• Referential Integrity
![Page 6: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/6.jpg)
Query Language
• Interface between the user and the data base.
• A query Is a statement written in query language for retrieval od data from database.
![Page 7: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/7.jpg)
![Page 8: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/8.jpg)
INTRODUCTION
![Page 9: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/9.jpg)
Select
• Select
• Select operation selects the rows that satisfy a given predicate (condition).
• The Greek letter sigma is used to denote the select operation.
• Syntax:
![Page 10: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/10.jpg)
• Find the students from the student relation who belong to qadian CITY.
![Page 11: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/11.jpg)
![Page 12: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/12.jpg)
![Page 13: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/13.jpg)
Project
• Use to select attributes from the relation
![Page 14: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/14.jpg)
![Page 15: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/15.jpg)
![Page 16: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/16.jpg)
Rename
• Used for following
• 1. When we want to change the name of any existing relation
• 2. When we want to give a name to a new relation which is obtained as a result of any relational algebra expression
![Page 17: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/17.jpg)
![Page 18: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/18.jpg)
Cartesian Product
• Cartesian product is denoted by cross (×) and it combines the information from any two relations.
• Cartesian product of two relations R and S is denoted as R×S, which result in a new relation that contains all the possible combinations of tuples in R and S.
![Page 19: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/19.jpg)
• Degree or arity (P) = arity(R) + arity(S)
• Cardinality (P) = cardinality(R) * cardinality(S)
![Page 20: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/20.jpg)
![Page 21: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/21.jpg)
![Page 22: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/22.jpg)
Union
• the union of two sets results in a new set that contains all the elements belonging to both the sets but does not include the duplicate elements
![Page 23: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/23.jpg)
![Page 24: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/24.jpg)
![Page 25: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/25.jpg)
Set Difference
• the difference of two sets results in a new set that contains all the elements of first set which are not present in the second set.
![Page 26: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/26.jpg)
![Page 27: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/27.jpg)
Intersection
• Intersection of two sets results in a new set which contains the common elements from both the sets.
![Page 28: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/28.jpg)
![Page 29: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/29.jpg)
Natural Join
• Join operation allows us to combine certain selections and cartesian product into one operation.
![Page 30: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/30.jpg)
![Page 31: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/31.jpg)
• Example: Show all the customers who have an account and also have taken a loan.
![Page 32: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/32.jpg)
![Page 33: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/33.jpg)
Outer Join
• Outer-join operation is an extension of natural join which deals with missing information.
![Page 34: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/34.jpg)
![Page 35: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/35.jpg)
![Page 36: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/36.jpg)
![Page 37: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/37.jpg)
![Page 38: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/38.jpg)
![Page 39: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/39.jpg)
![Page 40: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/40.jpg)
Division
• The division operation is suited to the queries that include the phrase “for all”.
![Page 41: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/41.jpg)
![Page 42: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/42.jpg)
![Page 43: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/43.jpg)
![Page 44: Relational Algebra - LPU GUIDE...which is obtained as a result of any relational algebra expression Cartesian Product •Cartesian product is denoted by cross ×) and it combines the](https://reader033.vdocuments.us/reader033/viewer/2022060907/60a1fa5220634676056f89b9/html5/thumbnails/44.jpg)