Download presentation

Presentation is loading. Please wait.

Published byThaddeus Potterton Modified over 2 years ago

1
Relational Algebra Rohit Khokher

2
Relational Algebra Set Oriented Operations UnionIntersectionDifference Cartesian Product Relation Oriented Operations SelectProjectRenameJoinDivision

3
Relational algebra Types of operations Set theoretic operations Union operator Intersection operator Difference operator Cartesian product operator Selection operator Project operator Joins Division operation Some examples

4
Union, Intersection and Difference Operands need to be union compatible for the result to be a valid relation Definition : Two relations R1 and R2 are union compatible iff: They have the same number of attributes. Corresponding fields have the same type.

5
The result R1 R2 is a relation that includes all tuples that are either in R1 or in R2 or in both without duplicate tuples. The resulting relation might have the same attribute names as the first or the second relation.

6
R1 R2 R1 U R2

7
The result R1 R2 is a relation that includes only those tuples : That are in R1 and also appear in R2. The resulting relation might have the same attribute names as the first or the second relation

8
R1 R2

9
The result R1 R2 is a relation that: includes all tuples that are in R1 and not in R2 The resulting relation might have the same attribute names as the first or the second relation

10
R1 R2 R1-R2

11
Definition: Result schema has one field per field of P and Q, with field names `inherited’ if possible. The result, denoted by PXQ, is a relation that includes all the possible combinations of tuples from P and Q Used in conjunction with other operations

12
X PQ

13
Selects rows that satisfy selection condition. No duplicates in result! Schema of result identical to schema of (only) input relation. Result relation can be the input for another relational algebra operation! (Operator composition.)

14
S

15
Deletes attributes that are not in projection list. Schema of result contains exactly the fields in the projection list, with the same names that they had in the (only) input relation. Result = (attribute list) (relation name) Resulting relation has only the attributes in the list, in same order as they appear in the list the degree(result) = number of attributes in the attribute list no duplicates in the result attribute list are drawn from the specified relation ;

16
S

17
stands for the usual comparison operators ‘ ‘, ‘>=‘, etc The result is a concatenated set but only for those tuples where the condition is true. It does not require union compatibility of R1 and R2 Result = R1 ( join condition) R2 Fewer tuples than cross-product, might be able to compute more efficiently

18
R1 S1

19
Definition: The division of two relations R1(A 1,A 2,...,A n ) with cardinality i and R2(B 1,B 2,...,B m ) with cardinality j is a relation R3 with degree k=n-m, cardinality i*j and attributes (A 1,A 2,...,A n,B 1,B 2,...,B m ) that satisfy the division condition The principle algebraic counterpart of queries that involve the universal quantifier Relational languages do not express relational division

20
A B1 A/B1 B2 A/B2 B3 A/B3

21
Sailors: ( sid, sname, rating, age ) Boats: ( bid, color, bname ) Reserves: ( sid, bid, date )

22
Solution 1:

23
Information about boat color only available in Boats; so need an extra join: A more efficient solution:

24
Can identify all red or green boats, then find sailors who’ve reserved one of these boats: What happens if is replaced by in this query?

25
Previous approach won’t work! Must identify sailors who’ve reserved red boats, sailors who’ve reserved green boats, then find the intersection (note that sid is a key for Sailors):

Similar presentations

OK

1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.

1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on history of atoms Ppt on 2 stroke ic engine works Insect anatomy and physiology ppt on cells Ppt on old movies vs new movies Ppt on financial services in india Ppt on topic health and medicine Collaborative strategic reading ppt on ipad Ppt on effects of world war 1 Ppt on principles of object-oriented programming for dummies Ppt on airbag working principle