Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra CIS 4301 Lecture Notes Lecture 14 - 2/28/2006.

Similar presentations


Presentation on theme: "Relational Algebra CIS 4301 Lecture Notes Lecture 14 - 2/28/2006."— Presentation transcript:

1 Relational Algebra CIS 4301 Lecture Notes Lecture 14 - 2/28/2006

2 Lecture 14© CIS 4301 - Spring 20062 Sample Relational Schema Movie (Title,Year,length,filmType, studioName,producerC#) StarsIn (MovieTitle,MovieYear,StarName) MovieStar(Name,address,gender,birthdate) MovieExec(name,address,Cert#,netWorth) Studio (Name,address,presC#)

3 Lecture 14© CIS 4301 - Spring 20063 Relational Operator: Rename The unary rename operator gives a new schema to a relation  S(A 1, A 2, …, A n ) (R) Renames relation R to S with attributes A 1, A 2, …, A n Note: S has exactly the same tuples as R Also, note the implicit rename operation in our notation from lecture 15 S(A 1, A 2, …, A n ) := R is shorthand notation for  S(A 1, A 2, …, A n ) (R)

4 Lecture 14© CIS 4301 - Spring 20064 Example  MyStarsIn(Title, Year, MoviedStar) (StarsIn) MovieTitle MovieYear StarName Title Year MovieStar Star Wars 1977 H. Ford Star Wars 1977 H. Ford Star Wars 1977 C. Fisher Star Wars 1977 C. Fisher StarsIn MyStarsIn

5 Lecture 14© CIS 4301 - Spring 20065 Complex Expressions Form expressions of arbitrary complexity by applying operators either to given relations or to relations that are the result of applying one or more relational operators to relations Three notations for expressing sequence of operations (just like in arithmetic) Sequence of assignment statement Use assignment operator ‘:=’ to assign relation to a relation variable Expression with several operators Using parentheses as necessary Expression tree

6 Lecture 14© CIS 4301 - Spring 20066 Example “What are the stars of movies that are at least 100 minutes long?”

7 Lecture 14© CIS 4301 - Spring 20067 Sequence of Assignment Statements Find the address of the studio who produced the Star Wars movie made in 1977.

8 Lecture 14© CIS 4301 - Spring 20068 Expression in Single Assignment Express previous query as single expression: What about precedence? Option 1: Use parenthesis to make precendence clear Option 2: Use precedence rules for relational operators Unary operators have highest precedence, bind first Next come product and joins Then intersection Finally, union and set difference bind last

9 Lecture 14© CIS 4301 - Spring 20069 Expression Tree Leaves are operands Either variables standing for relations or for particular constant relations Interior nodes are operators, applied to their child or children Example: Find all the producers of movies in which H. Ford played whose networth is greater than $10M

10 Lecture 14© CIS 4301 - Spring 200610 Exercise Find movie star executive producer pairs who live at the same address?

11 Lecture 14© CIS 4301 - Spring 200611 Dependent and Independent Operations Union, difference, selection, projection, cartesian product, and renaming form an independent set of operations None of them can be written in terms of the other five Can you express R  S R join  =c S R join S in terms of the 5 independent operations?


Download ppt "Relational Algebra CIS 4301 Lecture Notes Lecture 14 - 2/28/2006."

Similar presentations


Ads by Google