Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine.

Similar presentations


Presentation on theme: "Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine."— Presentation transcript:

1 Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine

2 2 Database Management CH 6 Database State for COMPANY All examples discussed below refer to the COMPANY database Book Page 137.

3 3 University Of Palestine Database Management CH 6 Relational Algebra The basic set of operations for the relational model is known as the relational algebra. These operations enable a user to specify basic retrieval requests. The result of a retrieval is a new relation, which may have been formed from one or more relations. The algebra operations thus produce new relations, which can be further manipulated using operations of the same algebra. A sequence of relational algebra operations forms a relational algebra expression, whose result will also be a relation that represents the result of a database query (or retrieval request).

4 4 University Of Palestine Database Management CH 6 Relational Algebra Collection of operators that manipulate relations to produce relations as an output. 1.Operations that based on se theory: U  Union ∩  Intersect -  Minus X  Cross Product ÷  Devision 2.Operations that especialy designed for relational DB: σ  Select Π  Project ∞  Join ρ  rename ά  Simijoin G  Group by

5 5 University Of Palestine Database Management CH 6 Unary Relational Operations SELECT Operation SELECT operation is used to select a subset of the tuples from a relation that satisfy a selection condition. It is a filter that keeps only those tuples that satisfy a qualifying condition – those satisfying the condition are selected while others are discarded. Example1: To select the EMPLOYEE tuples whose department number is four, the following notation is used:  (EMPLOYEE)

6 6 University Of Palestine Database Management CH 6 Unary Relational Operations (Cont.) Example2: Retrieve employees whose salary is >1000 and they are working in department Number 5::  SALARY>=1000 and DNO = 4 (EMPLOYEE) Other Way:  SALARY>=1000  DNO = 4 (EMPLOYEE) 

7 7 University Of Palestine Database Management CH 6 Unary Relational Operations( Cont.) PROJECT Operation This operation selects certain columns from the table and discards the other columns. The PROJECT creates a vertical partitioning – one with the needed columns (attributes) containing results of the operation and other containing the discarded Columns. Example1: To list each employee’s first and last name and salary, the following is used:   LNAME, FNAME,SALARY ( EMPLOYEE )

8 University Of Palestine Database Management CH 6 Union Compatible Relations Two relations are union compatible if – Both have same number of columns – Attributes with the same name in both relations have the same domain Union compatible relations can be combined using union, intersection, and set difference

9 9 University Of Palestine Database Management CH 6 Relational Algebra If R and S are two relations, R X S is the set of all concatenated tuples, where x is a tuple in R and y is a tuple in S (R and S need not be union compatible) a b c d a b c d x1 x2 y1 y2 x1 x2 y1 y2 x3 x4 y3 y4 x1 x2 y3 y4 x3 x4 y1 y2 R S x3 x4 y3 y4 R  S

10 10 University Of Palestine Database Management CH 6 Relational Alegrbra Cartesian Product: R1XR2 Example4: Name of each employee and the name of his/her department:   FNAME,MINIT,LNAME,DNAME  DNO=DNUMBER ( EMPLOYEE X DEPARTMENT )  Example5: Name of each son and the name of his father/mother:   DEPENDENT_NAME,FNAME,MINIT,LNAME  ESSN=SSN and RELATIONSHIP=“SON” ( EMPLOYEE X DEPENDENT ) Example6: Name of each department and the name of its manager:   DNAME,FNAME,MINIT,LNAME  MGRSSN=SSN ( EMPLOYEE X DEPARTMENT )

11 11 University Of Palestine Database Management CH 6 Relational Alegrbra Example7: Name of each project and the name of its controlling department and the name of the department manager.   PNAME,DNAME,ENAME  MGRSSN=SSN  DNUM=DNUMBER ( PROJECT X DEPARTMENT )X EMPLOYEE )  Example8: The name of managers:   FNAME,MINIT,LNAME  SSN=MGRSSN ( EMPLOYEE X DEPARTMENT )


Download ppt "Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine."

Similar presentations


Ads by Google