140 likes | 148 Views
Learn the theoretical foundation behind relational databases and how to manipulate table contents using relational operators. Explore the use of union, intersect, difference, divide, product, project, select, and join operations.
E N D
Relational Algebra Theory behind the relational engine
Relational Set Operators • Relational algebra • Defines theoretical way of manipulating table contents using relational operators • Use of relational algebra operators on existing relations produces new relations:
Union Combines all rows from two tables, excluding duplicate rows. The tables must have the same attribute characteristics.
Intersect Yields only the rows that appear in both tables. The tables must have the same attribute characteristics. Difference Yields all rows in one table that are not found in the other table. Subtracts one table from the other. The tables must have the same attribute characteristics.
DIVIDE This uses one single-column table as the divisor and one 2-column table as the dividend. The tables must have a common column. The output of the operation is a single column with the values of column ‘a’ from the dividend tables rows where the value of the common column in both tables match.
Product Yields all possible pairs of rows from two tables – also known as Cartesian product. If one table has six rows and the other tables has three rows the resulting table will have 18 rows. 6 X 3 = 18
Project Yields all values for selected attributes. Yields a VERTICAL SUBSET of a table.
Select Also known as Restrict, yields values for all rows found in the table that satisfy a given condition. SELECT can be used to list all the row values or it can yield only those rows that match a specified criterion. Yields a HORIZONTAL SUBSET of a table.
Join Allows information to be combined from two or more tables. This is the real power behind the relational database, where independent tables can be linked by common attributes (PK to FK fields).
Relational Algebra Operators (continued) Combines every record with every record from each table First, a Product is completed.
Relational Algebra Operators (continued) Gets rid of every row where the PK/FK does not match Next, a SELECT occurs using the PK and FK as selection criteria.
Relational Algebra Operators (continued) Gets rid of the duplicated key Finally, we get rid of the extra column. Remember, project yields the vertical subset, which gets rid of one of the duplicate PK-FK fields.
Relational Algebra Operators (continued) Outer Joins are useful for finding values that cause referential integrity problems.