0% found this document useful (0 votes)
49 views4 pages

Lab1 RA Answer

This document discusses lab exercises on relational algebra queries and constraints. It includes 5 queries on a database schema with 5 relations (Movies, StarsIn, MovieStar, MovieExec, Studio) that are expressed using relational algebra operations like selection, projection, join, set operations. It also includes 5 examples of expressing constraints via relational algebra, checking that attributes are present in other relations and that only certain values are present for attributes.

Uploaded by

Tran Vu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views4 pages

Lab1 RA Answer

This document discusses lab exercises on relational algebra queries and constraints. It includes 5 queries on a database schema with 5 relations (Movies, StarsIn, MovieStar, MovieExec, Studio) that are expressed using relational algebra operations like selection, projection, join, set operations. It also includes 5 examples of expressing constraints via relational algebra, checking that attributes are present in other relations and that only certain values are present for attributes.

Uploaded by

Tran Vu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 1: An Algebraic Query Language

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 (cert#, name, address, netWorth)

Studio (name, address, presC#)

1. 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 the address of studio Film City.

πaddress(σname = ‘Film City’(Studio) )

3. List name and gender of stars that appeared in movies produced by Sony in 2005.

R1: = σstudioName = ‘Sony’ and year = 2005 (Movies)


R2: = R1 ⋈title = movieTitle and year = movieYear StarIn ⋈starName =
name(MovieStar)

ΠstarName, gender(R2)

4. Find name of executives that are worth more than Subhash Ghai.
R1 := ΠnetWorth (σname = ‘Subhash Ghai’ (MovieExec) )
Πname (σmovieExec.netWorth > R1.netWorth (MovieExec x R1))

5. List all the titles and years of movies that appeared in either the Movies or StarsIn
relation.

Πtitle, year (Movies) U Πtitle, year (StarIn)

2. How to express constraints via Relation Algebra


1. The producerC# component of each Movies tuple must also appear in the cert#
component of some MovieExec tuple.

Πproducer# (Movies) - Πcert# (MovieExec) = Φ

2. No two tuples of StarIn agree on three components MovieTitle, MovieYear, and


StarName.

σnRec > 1 (movieTitle, MovieYear, StarNameGcount(*) -> noRec(StarIn)) = Φ


3. A Movie star must appear in at least 10 movies.

σnRec < 10 (starName G count(*) -> noRec(StarIn)) = Φ

4. The only legal values for the gender attribute of MovieStar are ’ F ’ and ’ M ’.

σgender <> ‘F’ and gender <> ‘M’ (MovieStar) = Φ


5. The president of Studio must have a net worth at least $10.000.000.
σnetWord < 10.000.000 (Studio ⋈pres# = cert# MovieExec) = Φ
No Symbol Description
1 R1 U R2 Set union
2 R1 - R2 Set except
3 R1 ∩ R2 Set intersection
4 πL (R) Projection
5 σC(R2) Selection
6 R1 x R2 Product
7 R1 ⋈ R2 Natural join
8 R ⋈θS Join
9 ρR1(A1,…,An)(R) Rename
10 Φ Empty set
11 Gmaker, count(model) -> Aggregate
numberOfPcs(R) functions as
SUM, COUNT,
MIN, MAX,
AVG (group by
‘maker’)

You might also like