Relational Algebra What are the Operands of Relational Algebra? relations (constants or variables) What are the Operators of Relational Algebra? union intersection difference select project rename product join Union, Intersection, Difference Compute the Union, Intersection, and Difference of R and S. (remember to remove duplicates) R = A B 0 1 2 3 S = A B 0 1 4 5 R union S = A B 0 1 2 3 4 5 R intersect S = A B 0 1 R - S = A B 2 3 What must be true for Union, Intersection, Difference to be valid? the relations must have the same schemes (Union Compatible) Select What does the Select operator do? extracts rows or tuples from a relation Compute the result of the Select operation. (What's the symbol for Select?) select[D='M' or H='9'] CDH C D H 1 M 8 1 W 8 1 F 8 2 M 9 2 W 1 2 F 9 3 F 2 Project What does the Project operator do? extracts columns or attributes from a relation Compute the result of the Project operation. (What's the symbol for Project?) project[PN] SNAP S N A P 1 C 1 4 2 C 3 4 6 L 3 8 2 P 5 9 Classwork You may work with a partner. Evaluate the relational algebra expressions. select[C='1' and (G='B' or G='C')] CSG C S G 1 1 A 1 6 B 2 1 C 2 2 B 1 3 C 3 6 C project[CH] CDH project[D] (select[C='1'] CDH) C D H 1 M 8 1 W 8 1 F 8 2 M 9 2 W 1 2 F 9 3 F 2 Rename Compute the result of the Rename operation. (What's the symbol for Rename?) rename[S<-X](SP) S P 1 4 6 8 2 9 Why is Rename useful? 1. to make relations union compatible and product compatible 2. to make relations join on the desired attribute Cartesian Product Compute the Product of R and S. (What's the symbol for Product?) R = A B 1 2 2 2 S = C D 1 1 2 2 3 3 R x S = A B C D 1 2 1 1 1 2 2 2 1 2 3 3 2 2 1 1 2 2 2 2 2 2 3 3 What must be true for the Product operation to be valid? the relations must have no common attribute names (Product Compatible)