SlideShare a Scribd company logo
1 of 21
DBMS – Lecture 2 : Relational Algebra 
Lecture Plan 
• Relational Algebra (operators) 
• How it allows data independence 
For more visit: www.technotz.info
Recapitulate: Database Abstraction 
• We have seen relational model as an abstraction. 
• Q: How do we operate on the relations/tables? How do 
we access data? 
Ans: Use a language such as: 
- relational algebra 
- SQL 
For more visit: www.technotz.info
Relational Algebra 
• Queries can be expressed in relational algebra 
- To retrieve data from tables 
• Five operators 
- Project: Cutting a table vertically 
- Restrict or Select: Cutting horizontally 
- Cartesian-product: Putting two tables together 
- Union: Adding rows 
- Difference: Deleting rows 
For more visit: www.technotz.info
Project Operation 
Cuts a table vertically. 
• Retrieves some (or all) columns from a table R 
 Example: Retrieve rollno and address of each student 
PROJECT (rollno, name, student) 
or 
student [rollno, name] 
rollno name 
123 
45 
Ram 
Mohan 
For more visit: www.technotz.info
From our familiar relation: student 
rollno* name addr city birth date 
123 
45 
Ram 
Mohan 
30 MG Marg 
10 Laxmi Bai 
Hyd 
Dlh 
83-06-21 
83-09-26 
For more visit: www.technotz.info
Project Operation: Definition 
• Definition 
PROJECT (A1, ..., Ak, R) 
or 
R [A1, ..., Ak] 
- A1 to Ak are attribute names, 
- R is a relation/table. 
* Result: A table with all the rows of R but only k 
attributes (A1 to Ak) 
For more visit: www.technotz.info
Restrict or Select Operation 
Cutting a table horizontally 
• Retrieves some (or all) of the rows from a table R. 
- Those that satisfy a given condition. 
 Ex. Retrieve information about the student with rollno 45 
RESTRICT ((rollno = 45), student) 
rollno* name addr city birth date 
45 Mohan 10 Laxmi Bai Dlh 83-09-26 
For more visit: www.technotz.info
 Ex. Retrieve students from Hyderabad 
RESTRICT (city = 'Hyd', student) 
roll no* name addr city birth date 
123 Ram 30 MG 
Marg 
Hyd 83-06-21 
For more visit: www.technotz.info
RESTRICT (F, R) 
• F is a condition, and R a table 
• Condition F is: 
* Equality or inequality involving attributes and 
values 
 Ex. (A2 < 16) 
 Ex. (A2 = A3) 
* logical-and, logical-or or logical-not of 
conditions. 
 Ex. ( (A2 < 16) AND (A2 = A3) ) 
* Result: A table with all the attributes of R, but only 
those rows that satisfy condition. 
For more visit: www.technotz.info
Composition of Operations 
• Possible to combine the operations 
 Ex. Names of students from Hyderabad 
PROJECT (sname, RESTRICT (city = 'Hyd', student)) 
 Ex. Names of students from Hyderabad with roll no. greater 
than 50 
PROJECT (sname, 
RESTRICT ((city = 'Hyd') AND 
(rollno > 50), student) ) 
name 
Ram 
For more visit: www.technotz.info 
- Above condition has logical-and
Cross Product (*) 
• A "multiplication" of two relations (R, S): 
R * S 
- Let R have m attributes (A1 to Am) and r rows, 
- Let S have n attributes (B1 to Bn) and s rows, 
- Result of cross product (R * S) is a relation with 
 (m+n) attributes: A1 ... Am, B1 ... Bn 
 r * s rows 
* Every row of R is pasted with every row of S. 
For more visit: www.technotz.info
Cross Product Example 
S = PROJECT (rollno, name, student) 
S 
roll no name 
123 Ram 
45 Mohan 
enroll 
cno* rollno* grade 
IT365 123 
IT355 45 
IT365 45 
IT340 123 For more visit: www.technotz.info
Cross-Product: S * register 
rollno name cno* rollno* grade 
123 
Ram 
IT365 
123 
123 
Ram 
IT355 
45 
123 
Ram 
IT365 
45 
123 
Ram 
IT340 
123 
45 
Mohan 
IT365 
123 
45 
Mohan 
IT355 
45 
45 
Mohan 
IT365 
45 
45 
Mohan 
IT340 
123 
For more visit: www.technotz.info
Join Operation: Example 
Join relates rows of two tables on some columns. 
 Ex. Find rollno. and name of students enrolled in 
courses. 
JOIN ((S.rollno = enroll.rollno), S, enroll) (where S is a 
projection of student as above) 
rollno name cno grade 
123 
123 
45 
45 
Ram 
Ram 
Mohan 
Mohan 
IT365 
IT340 
IT355 
IT365 
* Take the cross-product of: S and enroll 
* Keep only those rows where rollno is the same. 
* Do not keep two columns for rollno 
- Both have same value in each row 
 Same as: PROJECT For more (rollno, visit: www.technotz.name, info 
cno, grade, 
(continue...)
...continued 
RESTRICT [ (S.rollno = enroll.rollno), S * enroll ] ) 
rollno name cno grade 
123 
123 
45 
45 
Ram 
Ram 
Mohan 
Mohan 
IT365 
IT340 
IT355 
IT365 
For more visit: www.technotz.info
Join Operation: Definition 
• Join of R1, R2 on some logic formula F: 
JOIN (F, R1, R2) 
• Join: is a combination of CROSS-PROD and 
RESTRICT. 
The above is same as: 
RESTRICT (F, R1 CROSS-PROD R2) 
or 
RESTRICT (F, R1 * R2) 
For more visit: www.technotz.info
Equi-join and Natural Join 
• Equi-join: A join operation in which F contains equality 
only. 
• Natural join: A join operation in which equi-join is 
performed over 
the same column names across two relations. 
 Example: 
JOIN ((student.rollno = enroll.rollno), student, 
enroll) 
same as: 
NATURAL-JOIN (student, enroll) 
For more visit: www.technotz.info
Union (U) Operation 
• Takes two tables R and S (with same columns) and pastes 
them 
horizontally 
(rows add up): R U S 
 Ex. Students doing AI (IT365), and students doing 
DBMS (IT355) 
courses 
PROJECT (rollno, RESTRICT (cno='IT365', enroll)) 
U 
PROJECT (rollno, RESTRICT (cno='IT355', enroll)) 
rollno rollno 
U rollno = 
123 
123 
45 45 
45 
For more visit: www.technotz.info
Difference (-) Operation 
• Takes two tables R and S (with same columns) and removes rows 
of S from 
rows of R: R - S 
 Ex. Students doing AI (IT365) but not DBMS (IT355). 
( PROJECT (rollno, RESTRICT (cno='IT365', enroll)) 
PROJECT (rollno, RESTRICT (cno='IT355', enroll)) ) 
rollno rollno rollno 
123 
- = 
45 123 
45 
For more visit: www.technotz.info
Rename Operation 
• This is used to give new names to columns. 
RENAME (A1 as B1, ... An as Bn, R) 
- Attributes A's are renamed to B's. 
For more visit: www.technotz.info
Conclusions 
• Relational algebra is a query language 
- Allows us to access or retrieve data from tables 
* Query is in terms of tables, attributes, etc. 
- Is independent of physical representation 
* Does not depend on what organization is used: 
 What kinds of files are used ? 
 Whether sequential, b-tree, or hashed ? 
• As a result: 
- When underlying file organization changed, 
- queries need not change 
For more visit: www.technotz.info

More Related Content

What's hot

Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusemailharmeet
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systemsjakodongo
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculusVaibhav Kathuria
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & CalculusAbdullah Khosa
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra IntroductionMd. Afif Al Mamun
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculusSalman Vadsarya
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbmsshekhar1991
 
A simple presentation on Relational Algebra
A simple presentation on Relational AlgebraA simple presentation on Relational Algebra
A simple presentation on Relational AlgebraArman Hossain
 
Relational algebra
Relational algebraRelational algebra
Relational algebrashynajain
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptxRUpaliLohar
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculusKumar
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)yourbookworldanil
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra pptGirdharRatne
 

What's hot (18)

Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
relational algebra
relational algebrarelational algebra
relational algebra
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra Introduction
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculus
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
A simple presentation on Relational Algebra
A simple presentation on Relational AlgebraA simple presentation on Relational Algebra
A simple presentation on Relational Algebra
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptx
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculus
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
 
1643 y є r relational calculus-1
1643 y є r  relational calculus-11643 y є r  relational calculus-1
1643 y є r relational calculus-1
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Ch2
Ch2Ch2
Ch2
 

Viewers also liked

Data integrity Dbms presentation 12 cs 18
Data integrity Dbms presentation 12 cs 18Data integrity Dbms presentation 12 cs 18
Data integrity Dbms presentation 12 cs 18Engr Imran Ashraf
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries LectureFelipe Costa
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mappingsaurabhshertukde
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMSkoolkampus
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMSkoolkampus
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationGuru Ji
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation LanguageJas Singh Bhasin
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Sql Authorization
Sql AuthorizationSql Authorization
Sql AuthorizationFhuy
 

Viewers also liked (20)

Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
Data integrity Dbms presentation 12 cs 18
Data integrity Dbms presentation 12 cs 18Data integrity Dbms presentation 12 cs 18
Data integrity Dbms presentation 12 cs 18
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
Advanced DBMS presentation
Advanced DBMS presentationAdvanced DBMS presentation
Advanced DBMS presentation
 
Acid properties
Acid propertiesAcid properties
Acid properties
 
Overview of security in DBMS
Overview of security in DBMSOverview of security in DBMS
Overview of security in DBMS
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
Dbms models
Dbms modelsDbms models
Dbms models
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Commands
CommandsCommands
Commands
 
Sql Authorization
Sql AuthorizationSql Authorization
Sql Authorization
 

Similar to DBMS : Relational Algebra

Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
Relational algebr
Relational algebrRelational algebr
Relational algebrVisakh V
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
Multiple graphs in openCypher
Multiple graphs in openCypherMultiple graphs in openCypher
Multiple graphs in openCypheropenCypher
 
Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationshindhe1098cv
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptMisganawAbeje1
 
R Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB AcademyR Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB Academyrajkamaltibacademy
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
hgvgvhbhv hvh h h h h h h h h h h h h .ppt
hgvgvhbhv hvh h h h h h h h h h h h h .ppthgvgvhbhv hvh h h h h h h h h h h h h .ppt
hgvgvhbhv hvh h h h h h h h h h h h h .pptShahidSultan24
 

Similar to DBMS : Relational Algebra (20)

Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
07.05 division
07.05 division07.05 division
07.05 division
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 
Relational Algebra1.ppt
Relational Algebra1.pptRelational Algebra1.ppt
Relational Algebra1.ppt
 
Relational Calculus
Relational CalculusRelational Calculus
Relational Calculus
 
Relational algebr
Relational algebrRelational algebr
Relational algebr
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
Algebra
AlgebraAlgebra
Algebra
 
Multiple graphs in openCypher
Multiple graphs in openCypherMultiple graphs in openCypher
Multiple graphs in openCypher
 
Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operation
 
Unit_3.pdf
Unit_3.pdfUnit_3.pdf
Unit_3.pdf
 
Relational Algebra.ppt
Relational Algebra.pptRelational Algebra.ppt
Relational Algebra.ppt
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.ppt
 
Unit 04 dbms
Unit 04 dbmsUnit 04 dbms
Unit 04 dbms
 
R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
R Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB AcademyR Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB Academy
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
hgvgvhbhv hvh h h h h h h h h h h h h .ppt
hgvgvhbhv hvh h h h h h h h h h h h h .ppthgvgvhbhv hvh h h h h h h h h h h h h .ppt
hgvgvhbhv hvh h h h h h h h h h h h h .ppt
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

DBMS : Relational Algebra

  • 1. DBMS – Lecture 2 : Relational Algebra Lecture Plan • Relational Algebra (operators) • How it allows data independence For more visit: www.technotz.info
  • 2. Recapitulate: Database Abstraction • We have seen relational model as an abstraction. • Q: How do we operate on the relations/tables? How do we access data? Ans: Use a language such as: - relational algebra - SQL For more visit: www.technotz.info
  • 3. Relational Algebra • Queries can be expressed in relational algebra - To retrieve data from tables • Five operators - Project: Cutting a table vertically - Restrict or Select: Cutting horizontally - Cartesian-product: Putting two tables together - Union: Adding rows - Difference: Deleting rows For more visit: www.technotz.info
  • 4. Project Operation Cuts a table vertically. • Retrieves some (or all) columns from a table R  Example: Retrieve rollno and address of each student PROJECT (rollno, name, student) or student [rollno, name] rollno name 123 45 Ram Mohan For more visit: www.technotz.info
  • 5. From our familiar relation: student rollno* name addr city birth date 123 45 Ram Mohan 30 MG Marg 10 Laxmi Bai Hyd Dlh 83-06-21 83-09-26 For more visit: www.technotz.info
  • 6. Project Operation: Definition • Definition PROJECT (A1, ..., Ak, R) or R [A1, ..., Ak] - A1 to Ak are attribute names, - R is a relation/table. * Result: A table with all the rows of R but only k attributes (A1 to Ak) For more visit: www.technotz.info
  • 7. Restrict or Select Operation Cutting a table horizontally • Retrieves some (or all) of the rows from a table R. - Those that satisfy a given condition.  Ex. Retrieve information about the student with rollno 45 RESTRICT ((rollno = 45), student) rollno* name addr city birth date 45 Mohan 10 Laxmi Bai Dlh 83-09-26 For more visit: www.technotz.info
  • 8.  Ex. Retrieve students from Hyderabad RESTRICT (city = 'Hyd', student) roll no* name addr city birth date 123 Ram 30 MG Marg Hyd 83-06-21 For more visit: www.technotz.info
  • 9. RESTRICT (F, R) • F is a condition, and R a table • Condition F is: * Equality or inequality involving attributes and values  Ex. (A2 < 16)  Ex. (A2 = A3) * logical-and, logical-or or logical-not of conditions.  Ex. ( (A2 < 16) AND (A2 = A3) ) * Result: A table with all the attributes of R, but only those rows that satisfy condition. For more visit: www.technotz.info
  • 10. Composition of Operations • Possible to combine the operations  Ex. Names of students from Hyderabad PROJECT (sname, RESTRICT (city = 'Hyd', student))  Ex. Names of students from Hyderabad with roll no. greater than 50 PROJECT (sname, RESTRICT ((city = 'Hyd') AND (rollno > 50), student) ) name Ram For more visit: www.technotz.info - Above condition has logical-and
  • 11. Cross Product (*) • A "multiplication" of two relations (R, S): R * S - Let R have m attributes (A1 to Am) and r rows, - Let S have n attributes (B1 to Bn) and s rows, - Result of cross product (R * S) is a relation with  (m+n) attributes: A1 ... Am, B1 ... Bn  r * s rows * Every row of R is pasted with every row of S. For more visit: www.technotz.info
  • 12. Cross Product Example S = PROJECT (rollno, name, student) S roll no name 123 Ram 45 Mohan enroll cno* rollno* grade IT365 123 IT355 45 IT365 45 IT340 123 For more visit: www.technotz.info
  • 13. Cross-Product: S * register rollno name cno* rollno* grade 123 Ram IT365 123 123 Ram IT355 45 123 Ram IT365 45 123 Ram IT340 123 45 Mohan IT365 123 45 Mohan IT355 45 45 Mohan IT365 45 45 Mohan IT340 123 For more visit: www.technotz.info
  • 14. Join Operation: Example Join relates rows of two tables on some columns.  Ex. Find rollno. and name of students enrolled in courses. JOIN ((S.rollno = enroll.rollno), S, enroll) (where S is a projection of student as above) rollno name cno grade 123 123 45 45 Ram Ram Mohan Mohan IT365 IT340 IT355 IT365 * Take the cross-product of: S and enroll * Keep only those rows where rollno is the same. * Do not keep two columns for rollno - Both have same value in each row  Same as: PROJECT For more (rollno, visit: www.technotz.name, info cno, grade, (continue...)
  • 15. ...continued RESTRICT [ (S.rollno = enroll.rollno), S * enroll ] ) rollno name cno grade 123 123 45 45 Ram Ram Mohan Mohan IT365 IT340 IT355 IT365 For more visit: www.technotz.info
  • 16. Join Operation: Definition • Join of R1, R2 on some logic formula F: JOIN (F, R1, R2) • Join: is a combination of CROSS-PROD and RESTRICT. The above is same as: RESTRICT (F, R1 CROSS-PROD R2) or RESTRICT (F, R1 * R2) For more visit: www.technotz.info
  • 17. Equi-join and Natural Join • Equi-join: A join operation in which F contains equality only. • Natural join: A join operation in which equi-join is performed over the same column names across two relations.  Example: JOIN ((student.rollno = enroll.rollno), student, enroll) same as: NATURAL-JOIN (student, enroll) For more visit: www.technotz.info
  • 18. Union (U) Operation • Takes two tables R and S (with same columns) and pastes them horizontally (rows add up): R U S  Ex. Students doing AI (IT365), and students doing DBMS (IT355) courses PROJECT (rollno, RESTRICT (cno='IT365', enroll)) U PROJECT (rollno, RESTRICT (cno='IT355', enroll)) rollno rollno U rollno = 123 123 45 45 45 For more visit: www.technotz.info
  • 19. Difference (-) Operation • Takes two tables R and S (with same columns) and removes rows of S from rows of R: R - S  Ex. Students doing AI (IT365) but not DBMS (IT355). ( PROJECT (rollno, RESTRICT (cno='IT365', enroll)) PROJECT (rollno, RESTRICT (cno='IT355', enroll)) ) rollno rollno rollno 123 - = 45 123 45 For more visit: www.technotz.info
  • 20. Rename Operation • This is used to give new names to columns. RENAME (A1 as B1, ... An as Bn, R) - Attributes A's are renamed to B's. For more visit: www.technotz.info
  • 21. Conclusions • Relational algebra is a query language - Allows us to access or retrieve data from tables * Query is in terms of tables, attributes, etc. - Is independent of physical representation * Does not depend on what organization is used:  What kinds of files are used ?  Whether sequential, b-tree, or hashed ? • As a result: - When underlying file organization changed, - queries need not change For more visit: www.technotz.info