Download presentation
Presentation is loading. Please wait.
1
04 SQL & Relational Algebra
And Franchise Colleges HSQ - DATABASES & SQL 04 SQL & Relational Algebra By MANSHA NAWAZ Section 04 Relational Algebra
2
SQL & Relational Algebra
Two data manipulation languages proposed by Codd: Relational Algebra (How) Relational Calculus (What) SQL provides implementation of both Both based on the concept of Relational Closure: Relation Operation Section 04 Relational Algebra
3
Relational Algebra Several Operators take in one or more tables, and produce a new table (without destroying the original ones) Resultant table is temporary e.g., for outputting data for reporting purposes or for use with another operator Operators are: Cartesian Product Union Difference Intersection Rows of/Restrict Columns of/Project Join Divide Section 04 Relational Algebra
4
<result table name> = Union of <table list>
Two tables with same columns (i.e., same number and columns with matching domains) Output table is with same attributes with all rows in either or both of the input tables <result table name> = Union of <table list> Past_Emp: Present_Emp Q: R1 = Union of Past_Emp, Present_Emp Section 04 Relational Algebra
5
<result table name> = Intersection of <table list>
Two tables with same columns (i.e., same number and columns with matching domains) Output table is with same attributes with common rows from the input tables only <result table name> = Intersection of <table list> Past_Emp: Present_Emp Q: R1 = Intersection of Past_Emp, Present_Emp Section 04 Relational Algebra
6
Rows of (Select) One input table only Output table is with same attributes as input table but only with those rows that satisfy the given condition <result table name> = Rows of <table> where <condition> Received_Order: Q: R1 = Rows of Received_Order where quantity >= 100 Section 04 Relational Algebra
7
Columns of (Project) One input table only. Output table contains only those columns that are specified <result table name> = Columns of <table> under <attribute list> Q: R1 = Columns of Received_Order under Part# Received_Order: Q: duplicates? Section 04 Relational Algebra
8
Join Two tables required not necessarily with the same attributes but at least one attribute in each table that has the same domain Output table has all the attributes in the two tables (possibly minus the common attribute, depending on the join type) with the rows combined on the attributes specified in the “on” clause <result table name> = Join of <table> on <attribute list> Section 04 Relational Algebra
9
Q: R1 = Join of Received_Order, Part on Part#
Section 04 Relational Algebra
10
R1: This is a Natural join This is an Equi- join R1: Section 04
Relational Algebra
11
The previous ones were Inner joins
This is an Outer join The previous ones were Inner joins Section 04 Relational Algebra
12
Some tasks to try Supplier: Q: Find the part# of those parts that have been supplied by “S3” Q: Find the names of those parts that were supplied in a quantity greater than 100 Q: Find the names of the suppliers who have supplied bolts in quantities less than 200 and have been supplying for longer than 10 years NB Importance of order of the statements Section 04 Relational Algebra
13
Summary Relational Algebra Union Difference Intersection
Rows of/Restrict Columns of/Project Join Section 04 Relational Algebra
14
End of Lecture Section 04 Relational Algebra
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.