Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra References:

Similar presentations


Presentation on theme: "Relational Algebra References:"— Presentation transcript:

1 Relational Algebra References:
Databases Illuminated by Catherine Ricardo, published by Jones and Bartlett in 2004 Fundamentals of Relational Databases by Ramon A. Mata-Toledo and Pauline K. Cushman, published by McGraw Hill in Schaum’s Outline Series in 2000 Database Processing, Fundamentals, Design, and Implementation, Eighth Edition, by David M. Kroenke, published by Prentice Hall in 2002

2 Important Concept Relational algebra is similar to high school algebra except that the variables are tables not numbers and the results are tables not numbers.

3 Definition “Relational algebra is a theoretical language with operators that are applied on one or two relations to produce another relation.” Ricardo p. 181 Both the operands and the result are tables 8 operations originally proposed by Date

4 About Relational Algebra
? Non/procedural or procedural language ? Not implemented in native form in DBMS Basis for other HL DMLs

5 Operations SELECT PROJECT JOIN

6 OPERATORS Can be used in forming complex conditions
<, <=, >, >=, =, ≠, AND, OR, NOT

7 SELECT “The SELECT command is applied to a single table and takes rows that meet a specific condition copying them into a new table.” Ricardo p. 182 Informal general form: SELECT tableName WHERE condition [GIVING newTableName] Ricardo p. 182 Symbolic form σ EmpDept = 10 (EMPLOYEE) Mata-Toledo p. 37 Gives new table Square brackets indicate optional part of command

8 PROJECT “The PROJECT command also operates on a single table, but it produces a vertical subset of the table, extracting the values of specified columns, eliminating duplicates, and placing the values in a new table. Informal general form: PROJECT tableName OVER(colName,…,colName) [GIVING newTableName] Ricardo p. 183 Example of symbolic form π Location (DEPARTMENT) Mata-Toledo p. 38 Brackets mean optional part of statement

9 COMBINING SELECT AND PROJECT
Requires two steps Operation is not commutative Example using general form SELECT STUDENT WHERE Major = ‘History’ GIVING Temp PROJECT Temp OVER (LastName, FirstName,StuId) GIVING Result Example in symbolic form π LastName,FirstName, StuID(σMajor = ‘History’(STUDENT))

10 JOIN The JOIN operation is a combination of the product, selection and possible projection operations. The JOIN of two relations, say A and B, operates as follows: First form the product of A times B. Then do a selection to eliminate some tuples (criteria for the selection are specified as part of the join) Then (optionally) remove some attributes by means of projection.

11 Relation Operations Cartesian Product or Product
The cartesian product of two relations is the concatenation of every tuple of one relation with every tuple of a second relations. The cartesian product of relation A (having m tuples) and relation B (having n tuples) has m times n tuples. The cartesian product is denoted A X B or A TIMES B.

12 JOIN Comes in many flavors THETA JOIN – is the most general.
It is the result of performing a SELECT operation on the product Equivalent Examples: Student TIMES Enroll WHERE credits > 50 Student TIMES Enroll GIVING Temp SELECT Temp WHERE credits > 50 σ credits> 50 (Student X Enroll) A Xθ B = σ θ (A X B) EQUIJOIN is a theta join in which the theta is equality on the common columns Student EQUIJOIN Enroll Student XStudent.stuId=Enroll.stuIdEnroll Student Times Enroll GIVING Temp3 SELECT Temp3 WHERE Student.stuId = Enroll.stuID σ Student.stuId=Enroll.stuId (Student X Enroll) NATURAL JOIN is an equijoin in which the repeated column is eliminated. This is the most common form of the join operation and is usually what is meant by JOIN Example: tableName1 JOIN tableName2 [ GIVING newTableName]


Download ppt "Relational Algebra References:"

Similar presentations


Ads by Google