Uploaded by Bui Khanh Duy (K18 HL)

Lab1 - DBI

advertisement
Lab 1: An Algebraic Query Language
I.
We have the database schema consists of five relations:
Movies (title, year, length, genre, studioName, producer#)
StarsIn (movieTitle, movieYear, starName)
MovieStar (name, address, gender, birthdate)
MovieExec (producer#, name, address, netWorth)
Studio (name, address, presC#)
Write expressions of relational algebra to answer the following queries.
1. Find title and length of movies produced by Disney in 1990.
π title, length (σ studioName='Disney' ∧ year=1990 (Movies))
2. Find date of birth of Aishwarya Rai who is a movie star.
π birthdate (σ name='Aishwarya Rai' (MovieStar))
3. Find the address of studio Film City.
π address (σ name='Film City' (Studio))
4. List name of the female stars in the film “Monsoon Wedding”.
π starName (σ gender='Female' and σ movieTitle='Monsoon Wedding' (MovieStar
⨝ StarsIn))
5. List name and gender of stars that appeared in movies produced by Sony in 2005.
π starName, gender (σ studioName='Sony' ∧ year=2005 (Movies ⨝ StarsIn ⨝
MovieStar))
6. Find name of the producer of Star Wars.
π name (σ movieTitle='Star Wars' (Movies ⨝ MovieExec))
7. Find name of executives that are worth more than Subhash Ghai.
π name (σ netWorth > (σ name='Subhash Ghai' (MovieExec)) (MovieExec))
8. Find title of movies that are no longer than “Bride and Prejudice”.
π title (σ title='Bride and Prejudice' (Movies))
9. List all the titles and years of movies that appeared in either the Movies or StarsIn
relation.
π title, year (Movies) ∪ π movieTitle as title, movieYear as year (StarsIn)
10. Find name and address of all male movie stars who are also movie executives with
a net worth under $10,000,000.
π name, address (σ gender='Male' ∧ netWorth < 10000000 (MovieStar ⨝
MovieExec))
II.
How to express constraints via Relation Algebra
Give a schema:
PRODUCT (Maker, model)
PC (Model, Speed, RAM, HDD, Price)
LAPTOP (Model, Speed, RAM, HDD, Screen, Price)
PRINTER (Model, Color, Type, Price)
Use Relational Algebra to express following constraints:
1. A black & white printer must be laser type
2. If a laptop has a larger (or equal) RAM and HDD than a PC, then the laptop must
also have a higher price than the PC
3. No manufacturer of PC’s or Laptop’s may also make printers
4. With the same Speed, a PC must have higher RAM and HDD than a Laptop
5. With all computer (PC and Laptop), higher Speed, higher Price.
6. All model of product (PC or Laptop or Printer) in PC, Laptop and Printer relation
must appear in Product relation.
Download