Presentation is loading. Please wait.

Presentation is loading. Please wait.

1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational.

Similar presentations


Presentation on theme: "1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational."— Presentation transcript:

1 1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational Algebra Of course, we are still using Kroenke’s slide format!

2 1-2 Today’s Objectives To discuss different types of languages used for data manipulation To understand the meaning of relational completeness To understand closure To understand the results produce by relational algebra operations To form queries in the relational algebra

3 1-3 Types of Data Manipulation Languages (DML) Relational Algebra  (Codd 1971) Procedural language used to tell the DBMS HOW to retrieve information Relational Calculus  (Codd 1971) Non- procedural language for expressing WHAT we want, not how to get it Transform Oriented Language  language used to transform input data expressed as relations into results expressed as single relations Query-By-Example (QBE)  Graphical interface to allow user to request data.

4 1-4 Relational Completeness A language that can be used to produce any relation that can be derived using the relational calculus. Examples: Transform oriented and QBE These can in fact do more such as calculations and ordering SELECT sid, name FROM STUDENT ORDER BY sid;

5 1-5 Closure 3 + 4 = 7  closure Given R and S are relations and op is some relational algebra operation R op S  T where T is also a relation : closure

6 1-6 Relational Algebra Operators Codd 1972 Unary operations: Selection and Projection Binary operations: Union, Set Difference, Intersection, Cartesian Product, Join

7 1-7 Selection Let R be a relation such that R(r 1, r 2,…r n ) Selection:  predicate (R)  returns those tuples of R that satisfy the condition List all staff information for the company’s managers.  position = ‘Manager’ (Staff) SIDCourseIDGradeSemester 109CSCI332420057 102CSCI220320037 240CSCI362420051  grade >= 3 (Grades) 

8 1-8 Projection Projection:  r1, r2..ri (R)  returns the specified attributes from the relation R as a new relation  name (Student)  Produce a list of the names and addresses of all private owners  name, address (PrivateOwner) name Brian Jeff Michael Robert Peter

9 1-9 Union Compatible Let R & S be relations such that R(r 1, r 2,…r n ) & S(s 1,s 2,.. s m ) R and S are said to be union compatible if 1.n=m 2.domain(r i ) = domain(s i ) To force union compatibility, consider using projection. E.g. R   fName, iName, (Staff) S   fName, iName, (Client) R & S are union compatible

10 1-10 Union Let R & S be two relations that are union compatible Union: R  S  returns all tuples that are in both R and S with duplicate tuples eliminated List all cities where there is a branch office OR a property for rent  city (Branch)   city (PropertyForRent) List names of people who are a client or a private owner.  fName, iName, (Client)   fName, iName, (PrivateOwner)

11 1-11 Set Difference Let R & S be two relations that are union compatible Intersection: R - S  returns all tuples that are in R but not in S List all cities where there is a branch office but no properties for rent.  city (Branch) -  city (PropertyForRent) List the names of all clients who are not property owners.  fName, iName, (Client) -  fName, iName, (PrivateOwner)

12 1-12 Intersection Let R & S be two relations that are union compatible Intersection: R  S  returns all tuples that are in both R and S (where R & S intersect) List all cities where there is a branch office AND a property for rent  city (Branch)   city (PropertyForRent) List names of all people who are a client and a private owner.  fName, iName, (Client)   fName, iName, (PrivateOwner)

13 1-13 Intersection cont’d Intersection can be expressed using difference R  S = R – (R – S)  city (Branch)   city (PropertyForRent) =  city (Branch) – (  city (Branch) –  city (PropertyForRent) )

14 1-14 Division Let R & S be two relations where R is binary and S is unary. The attribute of S is a subset of the attributes of R. Divide: R  S  returns a relation consisting of all values of 1 attribute from R that match (in the other attribute) all values in the unary relation Identify all clients who have viewed all properties with three rooms. S then is all properties with 3 rooms, R is the list of clients and the properties they have viewed.  clientNp,propertyNo, (Viewing))   propertyNo (  rooms = 3 (PropertyForRent))

15 1-15 Cartesian Product Let R & S be relations that are not necessarily union compatible Cartesian Product: R x S  returns a relation with all possible combinations of tuples from R & S  clientNo, fName,iName (Client) x  clientNo, propertyNo, comment (Viewing) (p.94) Selection on the Cartesian product results in useful information. List names and comments of all clients who have viewed a property.  Client.clientNo = Viewing.clientNo (  clientNo, fName,iName (Client) x  clientNo, propertyNo, comment (Viewing))

16 1-16 Join Join is equivalent to performing a Selection over the Cartesian product of two relations Equijoin: R ⊳⊲ R.atti = S. attj S =  R.atti = S. attj (R x S)  returns a relation consisting of all possible combinations of tuples, one from each R & S, such that the two tuples contributing to any given combination satisfy the condition that related attributes are equal List names and comments of all clients who have viewed a property.  clientNp,fName, iName, (Client) ⊳⊲ Client.clientNo = Viewing.clientNo (  propertyNo, clientNo, comment (Viewing))

17 1-17 Natural Join Equijoin equivalent except duplicate attributes are removed. Represented using the same syntax as the Equijoin

18 1-18 Outer Join Outer join gaurantees that all tuples from one relation are represented even if they match no result from the other relation Equijoin: R ≻⊲ R.atti = S. attj S  returns a relation consisting of all tuples from R with information where available from S List names of all clients and, where applicable, comments they have made about properties viewed.  clientNp,fName, iName, (Client) ≻⊲ Client.clientNo = Viewing.clientNo (  propertyNo, clientNo, comment (Viewing))

19 1-19 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management End of Presentation: Chapter Four: Part One Of course, we are still using Kroenke’s slide format!


Download ppt "1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational."

Similar presentations


Ads by Google