This preview shows pages 1–7. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Remember from Friday Remember from Friday the Relational Algebra the Relational Algebra Procedural language Six basic operators select: project: union: set difference: Cartesian product: x rename: All of these operators except renaming ( ) take two relations as inputs and produce a new relation as a result. The renaming operator takes an expression in the relational algebra as an operand and returns the result of the expression under a new name and perhaps with attributes renamed as well. Composition of relational algebra operations is common! Formal Definition (from the text) Formal Definition (from the text) A basic expression in the relational algebra consists of either one of the following: A relation in the database A constant relation Let E 1 and E 2 be relationalalgebra expressions; the following are all relationalalgebra expressions: E 1 E 2 E 1 E 2 E 1 x E 2 p ( E 1 ), P is a predicate on attributes in E 1 s ( E 1 ), S is a list consisting of some of the attributes in E 1 x ( E 1 ), x is the new name for the result of E 1 Additional Operations Additional Operations Some operations built using the basic six are very convenient. They represent intuitively appealing operations that are often useful. So We define additional operations that do not add any power to the relational algebra, but that simplify common queries. Set intersection Natural join Division Assignment Set Set Intersection Operation Intersection Operation Notation: r s Defined as: r s = { t  t r and t s } Assume: r , s have the same arity attributes of r and s are compatible Note: r s = r ( r s ) Set Set Intersection Operation Intersection Operation Example Example Relation r, s : r s A B 2 3 s r A B 1 2 1 r  s A B 1 1 A B 2 Its easy to see that r (r s) is the same as r s In the marina scenario: In the marina scenario: Suppose that we want the names of all sailors who reserved a green boat and also reserved a red boat strategy: find all sailors who reserved a green boat find the boat numbers for all green boats pick sids from reservations records for these boats find the names of the sailors with these sids sname ( boat.color=green boat.bid=reserves.bidboat....
View
Full
Document
 Spring '08
 Conry

Click to edit the document details