Document 17544052

advertisement
Philadelphia University
Faculty of Information Technology
Department of Computer Science
761235 –Database Fundamentals
Relational Algebra Operators
Dr. Samir Tartir
Tuesday, 22/Dec/2015
1. SELECT: p (r)
 Use: When a subset of the rows is needed
 Rule: Same number of columns.
 Example: "… who have a salary greater than 500".
2. PROJECT: s(r)
 Use: When a subset of the columns is needed.
 Rule: Same number of rows - duplicates removed.
 Example: "Retrieve the name and ID of students who … "
3. PRODUCT: R x S
 Use: When the contents of two relations need to be joined completely (blindly)
 Rule: Columns = r + s, rows = r * s
4. UNION: r  s
 Use: Merging the contents of two relations
 Rule: Must be compatible (same number and types of columns)
 Example: "Show customers who have an account or a loan"
5. INTERSECTION: R  S
 Use: Showing the shared contents of two relations
 Rule: Must be compatible (same number and types of columns)
 Example: "Show customers who have an account and a loan"
6. DIFFERENCE: R – S
 Use: Showing the contents that exist in one relation but not the other
 Rule: Must be compatible (same number and types of columns)
 Example: "Show customers who have an account but don't have a loan"
7. RENAME:  x (R)
 Use: When the contents of the a relation are needed twice
 Rule: The new name is temporary and will be deleted after the query
8. Assignment: 
 Use: When the query is divided
 Rule: The new name is temporary and will be deleted after the query
9. DIVISION: r  s
 Use: When the data in one relation is related to all the data in another relation is needed.
 Rule: Number of columns in result = (r – shared)
 Example: "Show customers who have an account at all branches of the bank"
10. JOIN: r s
 Use: When the contents of two relations need to be merged (meaningfully)
 Rule: Number of columns in result = (r + s – shared)
 Example: "Show names of customers and the names of branches they have accounts in "
g
11. GROUP FUNCTIONS: G1, G2, …, Gn F1( A1), F2( A2),…, Fn( An) (E)
 Use: Showing groupings of data
 Rule: Functions: Avg, min, max, sum, count
 Example: "Show the average salary of employees"
Download