Uploaded by Đỗ Nhật Trung Anh

Lab1-Đỗ Nhật Trung Anh-HE171790

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. π(Movies.title, Movies.length) (σ(Movies.studioName = "Disney" AND
Movies.year = 1990) (Movies))
2. π(MovieStar.birthdate) (σ(MovieStar.name = "Aishwarya Rai") (MovieStar))Find
the address of studio Film City.
3. π(Studio.address) (σ(Studio.name = "Film City") (Studio))
4. π(StarsIn.starName) (σ(StarsIn.movieTitle = "Monsoon Wedding" AND
MovieStar.gender = "female") (StarsIn ⨝ MovieStar))
5. π(MovieExec.name) (σ(Movies.title = "Star Wars") (Movies ⨝ MovieExec))
6. π(MovieExec.name) (σ(MovieExec.netWorth > (σ(MovieExec.name = "Subhash
Ghai") (MovieExec))) (MovieExec))
7. π(Movies.title) (σ(Movies.length <= (σ(Movies.title = "Bride and Prejudice")
(Movies))) (Movies))
8. π(Movies.title, Movies.year) (Movies) ∪ π(StarsIn.movieTitle, StarsIn.movieYear)
(StarsIn)
9. π(MovieStar.name, MovieExec.address) (σ(MovieStar.gender = "male" AND
MovieStar.name = MovieExec.name AND MovieExec.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. π(PRINTER.Model) (σ(PRINTER.Color = "black & white" AND PRINTER.Type
<> "laser") (PRINTER))
2. ∀(LAPTOP l, PC p) (σ(l.Model = p.Model AND (l.RAM >= p.RAM AND l.HDD
>= p.HDD) AND l.Price <= p.Price) (LAPTOP ⨯ PC))
3. ∀(PC p, LAPTOP l, PRINTER pr) ((p.Maker = l.Maker OR p.Maker = pr.Maker
OR l.Maker = pr.Maker) = FALSE)
4. ∀(PC p, LAPTOP l) (σ(p.Speed = l.Speed AND (p.RAM <= l.RAM OR p.HDD
<= l.HDD)) (PC ⨯ LAPTOP))
5. ∀(PC p1, PC p2, LAPTOP l1, LAPTOP l2) (σ(p1.Speed > p2.Speed AND
p1.Price <= p2.Price) (PC ⨯ PC) = ∅) AND (σ(l1.Speed > l2.Speed AND l1.Price
<= l2.Price) (LAPTOP ⨯ LAPTOP) = ∅)
6. π(PC.Model) (PC) ∪ π(LAPTOP.Model) (LAPTOP) ∪ π(PRINTER.Model)
(PRINTER) = π(PRODUCT.Model) (PRODUCT)
Download