This assignment step is intended to strengthen your
understanding of Relational Schema for databases. In particular, understanding how to draw schema diagrams, recognize
primary keys and foreign key constraints.
Recall in class we defined relational algebra for the purpose of creating queries.
Here is a quick summary:
Notice the line in the table Theta Join. A Theta join is the same as
an inner join with an on condition
.
Write relational queries for each of the following. If it's not possible to write the
query using our relational algebra, simply say "not possible". You should submit your answers
in a PDF file called algebra.pdf
. You may do so using any editor of your choice
but you may find it easier to write in LaTeX.
You may use this starter file and
this online editor to write your LaTex code.
LaTeX allows for the very easy transcription of mathematical symbols.
- The names of the movies with genres comedy.
- Movie name, first and last names of the actors/actresses who play a role in a movie with rank at least 8.5.
- Movie names that had a rank less than 5 and were produced in the 70s (1970-1979).
- Last names of actresses (female role) who played a role in as Sci-Fi movie.
- Directors with more than one movies with rank > 9.
- Actor/Actress first and last names of actors/actresses who are also directors.
- The years that Robin Williams had a role in a movie.
- The actor/actress first and last name, movie title and role for all movies .
- The movie names of movies that are in the family genres but not comedies.
- In relational algebra and standard SQL the intersect and difference operators exist. Explain how you can implement each of these operations in MySQL.
Part 2: MySQL - Writing Queries
This assignment step is intended to strengthen your
understanding of writing queries in MySQL.
Write MySQL queries for the movies database for each of the following. Write your queries
in a file,
queries.sql
. Your filename must match
exactly.
You should have one query per line so that on the i
th line you have the query
for the i
th question below. If a query is not possible, then your query should return NULL.
Make sure you test your queries first on IMBD_SMALL and then on IMBD.
- The genre and number of movies of each genres.
- The first and last names played by female actors having role 'Wonder Woman'. Display first and last
name as a single column called Name.
- Movie names that had a rank at least 9.5 and were produced in the last 10 years (2007 and later).
- Directors and their movie names for movies with name starting with the letter "Zz".
//- Directors and their movie titles for movies with a rank of 9.5 or better.
- Actors first and last names as a column Name who play themselves (ie, role is Himself).
- The Director first and last name and average rank of movies for that director.
- The Director first and last name with the highest average rank of movies all directors.
- Create a view called max_roles of all actors/actresses who have had more than 300 roles.
- Using your view, return the actor/actress first and last name for actor/actress who have played themost roles.
- All those movie titles that are both comedies and action movies. Do NOT use
IN
.
- All those movie titles that are both comedies and action movies. USE
IN
.
- Some directors are actors/actresses too. Find all such director first and last names, the movies they acted in and their roles.
- The genre of movie that appears the most in the database.
- The names of those actors/actresses who had more than one role in the same
movie (like Robin Williams in Mrs. Doubtfire).
- The top 25 movie names (hint: look up the
limit
option).
Part 3: MySQL - Maintaining the Database
This assignment step is intended to strengthen your
understanding of writing create
, update
and insert
commands.
We are going to write the code as if we are adding a new table to the database.
You can test your code on the imbd_small
by importing a copy to your own account.
Write the following code in a
new file called maintain.sql
. Your filename must match exactly.
You should have one command per line.
- Create a new table that contains two columns with
the first being a
director_id
and the second being an average rank rating.
- Populate your table by using insert command(s) and the tables already in the database.
- Insert a the new movie Sing
that was just released. Find the appropriate information for our tables from the website. Note that
for the actors/actresses just add the stars (top three) listed. Note this will also require updating some tables.
Deliverables
Submit the following files to MarkUs.
algebra.pdf
queries.sql
maintain.sql
Please do not place a solution to this
assignment online on a publicly-accessible Web site;
doing so will be considered a violation of the
Academic Code of Conduct.
Good Luck!