58% found this document useful (12 votes)
4K views3 pages

Lab 1: An Algebraic Query Language: I. We Have The Database Schema Consists of Five Relations

This document discusses using relational algebra to query a database schema about movies. It contains 10 queries over relations like Movies, StarsIn, and MovieStar. It also discusses using relational algebra to express constraints over relations like PC, Laptop, and Printer. 6 constraints are given, such as that a black and white printer must be laser type, and all models in the PC, Laptop and Printer relations must appear in the Product relation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
58% found this document useful (12 votes)
4K views3 pages

Lab 1: An Algebraic Query Language: I. We Have The Database Schema Consists of Five Relations

This document discusses using relational algebra to query a database schema about movies. It contains 10 queries over relations like Movies, StarsIn, and MovieStar. It also discusses using relational algebra to express constraints over relations like PC, Laptop, and Printer. 6 constraints are given, such as that a black and white printer must be laser type, and all models in the PC, Laptop and Printer relations must appear in the Product relation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 1: An Algebraic Query Language

Lê Hồng Bảo Ngân – DE150159 – SE1502

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”) and (year = 1990) (Movies))
2. Find date of birth of Aishwarya Rai who is a movie star.
πbirthday(σname = “Aishwararya 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”.
πname(σ(gender = female) and (movieTitle = “Monsoon Wedding”) (MovieStar ⋈ StarsIn))
5. List name and gender of stars that appeared in movies produced by Sony in 2005.
π name, gender (σ(studioName = “Sony”) and (year = 2005) (MovieStar ⋈ Movies ⋈ StarsIn ))
6. Find name of the producer of Star Wars.
π producer# (σtitle = “Star Wars” (MovieExec ⋈ Movies))
7. Find name of executives that are worth more than Subhash Ghai.
a = πnetWorth(σname = “Subhash Ghai” (MovieExec))
πname(σnetWorth > a (MovieExec))
8. Find title of movies that are no longer than “Bride and Prejudice”.
a = πlength(σtitle = “Bridge and Prejudice” (Movies))
πname(σlength ≤ a (Movies))
9. List all the titles and years of movies that appeared in either the Movies or StarsIn
relation.
π title, year (Movies) U πmovieTitle, movieYear (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 (MovieStar)) ⋂ πname, address (σnetWorth < $10,000,000
(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:.9ol;

1. A black & white printer must be laser type


σcolor = false (σtype ≠ laser (Printer)) = ф
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
σ(Laptop.RAM ≥ PC.RAM) and (Laptop.HDD ≥ PC.HDD) (σLaptop.price ≤ PC.price (Laptop x PC)) = ф
3. No manufacturer of PC’s or Laptop’s may also make printers
(πmaker (Laptop) U πmaker (PC)) ⋂ πmaker (Printer) = ф
4. With the same Speed, a PC must have higher RAM and HDD than a Laptop
σPC.speed = Laptop.speed (Laptop x PC) ⋂ σ(PC.RAM ≤ Laptop.RAM) and (PC.HDD ≤ Laptop.HDD)
(Laptop x PC) = ф
5. With all computer (PC and Laptop), higher Speed, higher Price.
(πmodel(σPC1.speed > PC2.speed (σPC1.price ≤ PC2.price(PPC1(model, speed, RAM, HDD, price) (PC) ⋈
PPC2(model, speed, RAM, HDD, price) (PC) )))) U
(πmodel(σLaptop1.speed > Laptop2.speed (σLaptop1.price ≤ Laptop2.price(PLaptop1(model, speed, RAM, HDD,
price) (Laptop) ⋈ PLaptop2(model, speed, RAM, HDD, price) (Laptop) )))) = ф
6. All model of product (PC or Laptop or Printer) in PC, Laptop and Printer relation
must appear in Product relation.
πmodel (Product) – (πmodel (PC) U πmodel (Laptop) U πmodel (Printer)) = ф

You might also like