SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
jakodongo
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
shekhar1991
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
shynajain
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculus
Kumar
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
yourbookworldanil
 

Mais procurados (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
 

Destaque

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
Engr Imran Ashraf
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
saurabhshertukde
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
koolkampus
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
koolkampus
 
Sql Authorization
Sql AuthorizationSql Authorization
Sql Authorization
Fhuy
 

Destaque (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
 

Semelhante a DBMS : Relational Algebra

Semelhante a 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
 

Último

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
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

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