Relational Algebra1Fall 2001 Database Systems 1Relational Algebra• A relation is a set of tuples. Each relationalalgebra operation takes as input a list ofrelations and produces a single relation.• General form:OperatorArguments (List of Relations) New Relation• After each operation, the remaining attributesare carried to the new relation. The attributesmay be renamed, but their domain remains thesame.Fall 2001 Database Systems 2Set Theoretic Operations• Regular set operations on relations• A set operation requires two participating relations R andS to be compatible– R and S should have the same attributes• R(Name:D1, Email:D2)• S(Name:D1, Email:D2, Address:D3)• T(Name:D1, Email:D4)• V(Name:D1, Email:D2)Which relations above are union (set operation)compatible?– Union compatibility may require type conversion(casting).
Relational Algebra15Fall 2001 Database Systems 29Problem 1Find the name and email of owners of items located in“Boston”A := Items WHERE Location = “Boston”B := A ¢¡ OwnersResult := B[Owners.Name, Owners.Email]Fall 2001 Database Systems 30Problem 2Find the identifiers and amount of bids placed bybuyer “Roberts”A := Buyers WHERE Name = “Roberts”B := A ¢¡ BidsResult := B[Bid, Amount]
Relational Algebra16Fall 2001 Database Systems 31Problem 3Find the names of buyers who placed a bid on an itemowned by “Brown”A := Owners WHERE Name = “Brown”B := (A ¢¡ Items) [Iid]C := B ¢¡ BidsResult := (C ¢¡ Buyers) [Buyers.Name]Fall 2001 Database Systems 32Problem 4Find the identifier of items with more than one bidA := Bids[Bid, Iid]B := A x Bids[Bid,Iid]C := B WHERE (A.Bid Bids.Bid)AND (A.Iid = Bids.Iid)Result := C[Iid]
Relational Algebra17Fall 2001 Database Systems 33Problem 5Find the names of items all buyers placed a bid onA := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid])B := A ¢¡ ItemsResult := B[Name]