Presentation is loading. Please wait.

Presentation is loading. Please wait.

603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.

Similar presentations


Presentation on theme: "603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems."— Presentation transcript:

1 603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems

2 Relational Algebra Chapter 5 Up to Now: *discussed concepts that the relational model provides for defining the structure and constraints of a relational database Now Relational Algebra: *when data are viewed as relations, it is possible to formulate queries utilizing the properties of relational theory

3 Relational Algebra Chapter 5 *Relational Algebra provides a powerful tool for such a view of the data for formulating real world concepts into queries which can be related to the data description *Set Operations and Operations developed specifically for relation databases

4 Relational Algebra Chapter 5 –This chapter develop database programming ==> used to facilitate the user asking queries of the database and modify the contents of the database –Begin by introducing the relational algebra operations –This algebra formally applies to sets of tuples –THE OPERATIONS OF RELATIONAL ALGEBRA ARE ALL IMPLEMENTED IN THE SQL QUERY LANGUAGE

5 Relational Algebra Chapter 5 Relational Algebra ==> Atomic operands are: 1.Variables that stand for relations R 2.Constants, which are finite relations Operations of Relational Algebra : 1.The usual set operations - union, intersection, and difference - applied to relations R 2.Operations that remove parts of a relation: Selection  and Projection 

6 Relational Algebra Chapter 5 * Selection  eliminates some rows (tuples) of R and * Projection  eliminates some columns (attributes) of R *Operations that combine the tuples of two relations R 1 and R 2, including “Cartesian Product,” which pairs the tuples of two relations in all possible ways, and various kinds of “join” operations, which selectively pair tuples from two relations

7 Relational Algebra Chapter 5 Set Operations on Relations R: *R  S, the union or R and S => the set of elements that are in R or S or both. An element appears only once in the union even if it is present in both R and S. S R Union

8 Relational Algebra Chapter 5 Set Operations continued: *R  S, the intersection of R and S => the set of elements that are in both R and S Intersection R S

9 Relational Algebra Chapter 5 R - S, the difference of R and S => the set of elements that are in R but not in S NOTE: When applying these set theoretic operations to relations, we need to put some conditions on R and S : 1. R and S must have schemas with identical sets of attributes, and the types(domains) for each attribute must be the same in R and S 2. Before we compute the set-theoretic union, intersection, or difference of sets of tuples, the columns of R and S must be ordered so that the order of the attributes is the same for both relations

10 Relational Algebra Chapter 5 FNAME MINIT LNAME SSN SEX SALARY DNO Franklin T Wong333445555M40000 5 Jennifer S Wallace987654321F43000 4 Ramesh K Narayan66688444M38000 5  DNO = 4 (EMPLOYEE)  SALARY > 3000 (EMPLOYEE) In General:  ( R ) EMPLOYEE

11 Relational Algebra Chapter 5 Select Operation: In General:  ( R ) The Boolean expression specified in is made up of clauses of the form or

12 Relational Algebra Chapter 5 SELECT Operator: => unary; that is, it is applied to a single relation => applied to each tuple individually NOTE: Selection conditions cannot involve more than one tuple The degree of the relation resulting from a SELECT operation is the same as that of R !

13 Relational Algebra Chapter 5 Selectivity of the condition: The fraction of tuples selected by a selection condition is referred to as the selectivity of the condition

14 Relational Algebra Chapter 5 Notice that the SELECT operation is commutative:  (  ( R )) =  (  ( R ))

15 Relational Algebra Chapter 5 PROJECT Operation: If we think of the relation R as a Table, the SELECT operation selects some of the rows for the table while discarding other rows The PROJECT operation, on the other hand, selects certain columns from the table and discards the other columns

16 Introduction to Relational Algebra (Chapter 5) Basic of Relational Algebra Set Operations on Relations Projection Selection Cartesian Product Natural Joins Theta-Joins

17 Relational Algebra Chapter 5 PROJECT Operation: List each employee’s first and last name and salary -  LNAME, FNAME, SALARY (EMPLOYEE) In general, the PROJECT Operator is:  (R)

18 Relational Algebra Chapter 5 PROJECT Operations: If the attribute list includes only nonkey attributes of R, duplicate tuples are likely to occur; the PROJECT operation removes any duplicate tuples, so the result of the PROJECT operation is a set of tuples and hence a valid relation  (  (R)) =  (R)

19 Relational Algebra Chapter 5 nameaddressgenderbirthdate Carrie Fisher123 Maple St. Holl.F9/9/99 Mark Hamill456 Oak Rd., Brent.M8/8/88 Relation S nameaddressgenderbirthdate Carrie Fisher123 Maple St., Holl.F9/9/99 Harrison Ford789 Palm Dr., B. H.M7/7/77 Relation R

20 Relational Algebra Chapter 5 R  S nameaddressgender birthdate Carrie Fisher123 Maple St., Holl.F9/9/99 Mark Hamill456 Oak Rd., Brent.M8/8/88 Harisson Ford789 Palm Dr., B. H.M7/7/77 R  S nameaddressgenderbirthdate Carrie Fisher123 Maple St., Holl.F9/9/99

21 Relational Algebra Chapter 5 R - S nameaddressgenderbirthdate Mark Hamill456 Oak Rd., Brent.M8/8/88

22 Relational Algebra Chapter 5 - Next Lecture Projection Selection Cartesian Product Natural Joins


Download ppt "603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems."

Similar presentations


Ads by Google