Download presentation

Presentation is loading. Please wait.

Published byRocio Bloor Modified over 3 years ago

1
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield

2
Study Objectives Learn about relational database algebra Understand Query-by-Example (QBE) Use Criteria in QBE Create Calculated Columns in QBE Calculate Statistics in QBE

3
Relational Algebra Relational algebra is a procedural query language. Relational algebra consists of a set of operations that take one or two relations as input and produce a new relation as their result. Relational algebra is a high level query language because operations are applied to entire relations. When specifying a relational algebra query, users must specifies how – in what order – to execute the query operations. Difficult and no standard method.

4
Relational Algebra (con’t) Most commercial relational DBMSs provide a high- level declarative language interface. So, the user only specifies what the result is… Leaving the actual optimization and decisions on how to execute the query to the DBMS.

5
Relational Algebra Operators The relational algebra consists of a collection of high-level operators that operate on relations. Each such operator takes either one or two relations as its input and produces a new relation as its output. The traditional set operations: union, intersection, difference, and (Cartesian) product. The special relational operations: select, project, join, and divide.

6
Set Theory The notation S T will mean that S is a subset of T. - e.g., {1, 2, 3} {1,2,3,4} If S is a subset of T and T contains at least one element that is not in S, then S is a proper subset of T. Notation for a proper subset is . - e.g., {1, 2, 3} {1,2,3,4}, {1, 2, 3} {1,2,3,4} are true. As far as a set is concerned, changing the order of elements does not change the set: e.g., {1, 2, 3} = {3, 2,1} Two set A and B are disjoint iff A B = .

7
Union (R1 U R2) Produces a relation that includes all the rows (tuples) in R1 or R2 or both R1 and R2 must be union-compatible (derived from the math). Union-compatible: Tables must have the same attributes characteristics to be used in the union. That is, columns and domains must have be identical such as name and format of the filed.

8
Union Combines all rows

9
Intersection (R1 R2) Produces a relation that includes only the tuples that appears in both R1 and R2; R1 and R2 must be union compatible.

10
Difference (R1 - R2 ) Produces a relation that includes all the tuples in R1 that are not in R2; R1 and R2 must be union compatible. How about R1 – R2?

11
Product (R1 X R2) Produces a relation that has the attributes of R1 and R2 and includes as tuples all possible combinations of tuples from R1 and R2. Build a relation from two specified relations consisting of all possible combinations of tuples, one from each of the two relations.

12
Product

13
Select ( (R)) Do not confused with one of the SQL commands “select” Select all tuples that satisfy the selection condition from a relation R. The restriction operator effectively yields a "horizontal" subset of a given relation -- that is, that subset of the tuples of the given relation for which a specified comparison is satisfied.

14
Yields a subset of rows based on specified criterion Select

15
Project ( (R)) Produce a new relation with only some of the attributes of R and remove duplicate tuples. The projection operator yields a "vertical" subset of a given relation --That is, that subset obtained by selecting specified attributes and then eliminating duplicate tuples within the attributes selected.

16
Yields all values for selected attributes Project

17
Requires user of single-column table and two-column table Divide

18
Information from two or more tables is combined Join

19
Inner Join the most common type of join. There must be a matching value in a field common to both tables. all employees working on each project who live in the same city as where the project is taking place: SELECT Username, ProjectName, Location FROM Employee INNER JOIN Project ON Employee.City = Project.Location;

20
Equi Join Equijoin means the join between tables where the values of two or more columns are equal. When a join condition relates two tables by an operator other than equality, it is a non-equijoin. SELECT e.first_name, d.department_name FROM employees INNER JOIN departments d ON e.department_id = d.department_id

21
Other Joins Theta JOIN EquiJOIN that compares specified columns of each table using operator other than equality one Outer JOIN Matched pairs are retained Unmatched values in other tables left null Right and left

22
Query-by-Example (QBE) Query Questions represented in a way the DBMS can recognize and process QBE Visual approach to writing queries Used in MS-Access

23
Simple Queries

24
Simple Queries (con’t.)

25
Query that Includes All Fields

26
Query with Simple Criteria

27
Query Using AND Criteria

28
Query Using OR Criteria

29
Query Using Two Conditions on a Single Field

30
Query Using Computed Field

31
Query to Count Records

32
Query to Calculate an Average

33
Query to Sort Records

34
Query to Sort on Multiple Keys

35
Query to Sort on Multiple Keys (con’t.)

36
Query to Join Tables

37
Query to Join Tables (con’t.)

38
Query to Restrict Records in a Join

39
Update Query

40
Delete Query

41
Make-Table Query

42
Make-Table Query (con’t.)

Similar presentations

Presentation is loading. Please wait....

OK

Concepts of Database Management Seventh Edition

Concepts of Database Management Seventh Edition

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Convert pdf ppt to ppt online shopping Ppt on earth hour wikipedia Ppt on human resources development Ppt on 60 years of indian parliament debate Ppt on global business communication Ppt on airbag working principle of motor Ppt on classical economics books Ppt on cartesian product symbol Civil engineering ppt on high performance concrete Ppt on remote operated spy robot controller