CSCB20 Assignment 1: Movie-Database Queries
Part 1 due Wed 1 Feb, 2017, 11:59pm
Part 2 due Saturday 11 Feb, 2017, 11:59pm

Part 1: Database Schema

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.

For this assignment step you will use the given relation schemas and draw a schema diagram. Your diagram should underline primary keys and link foreign key constraints as done in class with the university schema.

An IMDB Database

Consider the following movie website iMDB. This website uses a movie database. A possible set of relations for this database are below:

actors
idfirst_namelast_namegender
433259WilliamShatnerM
797926BritneySpearsF
831289SigourneyWeaverF
...
movies
idnameyearrank
112290Fight Club19998.5
209658Meet the Parents20007
210511Memento20008.7
...
roles
actor_idmovie_idrole
433259313398Capt. James T. Kirk
433259407323Sgt. T.J. Hooker
797926342189Herself
...
movies_genres
movie_idgenre
209658Comedy
313398Action
313398Sci-Fi
...
directors
idfirst_namelast_name
24758DavidFincher
66965JayRoach
72723WilliamShatner
...
movies_directors
director_idmovie_id
24758112290
66965209658
72723313398
...

Part 1: Relational Algebra

This assignment step is intended to strengthen your understanding of Relational Algebra and MySQL for databases.


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.

  1. The names of the movies with genres comedy.
  2. Movie name, first and last names of the actors/actresses who play a role in a movie with rank at least 8.5.
  3. Movie names that had a rank less than 5 and were produced in the 70s (1970-1979).
  4. Last names of actresses (female role) who played a role in as Sci-Fi movie.
  5. Directors with more than one movies with rank > 9.
  6. Actor/Actress first and last names of actors/actresses who are also directors.
  7. The years that Robin Williams had a role in a movie.
  8. The actor/actress first and last name, movie title and role for all movies .
  9. The movie names of movies that are in the family genres but not comedies.
  10. 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 ith line you have the query for the ith 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.

  1. The genre and number of movies of each genres.
  2. The first and last names played by female actors having role 'Wonder Woman'. Display first and last name as a single column called Name.
  3. Movie names that had a rank at least 9.5 and were produced in the last 10 years (2007 and later).
  4. Directors and their movie names for movies with name starting with the letter "Zz".
  5. //
  6. Directors and their movie titles for movies with a rank of 9.5 or better.
  7. Actors first and last names as a column Name who play themselves (ie, role is Himself).
  8. The Director first and last name and average rank of movies for that director.
  9. The Director first and last name with the highest average rank of movies all directors.
  10. Create a view called max_roles of all actors/actresses who have had more than 300 roles.
  11. Using your view, return the actor/actress first and last name for actor/actress who have played themost roles.
  12. All those movie titles that are both comedies and action movies. Do NOT use IN.
  13. All those movie titles that are both comedies and action movies. USE IN.
  14. Some directors are actors/actresses too. Find all such director first and last names, the movies they acted in and their roles.
  15. The genre of movie that appears the most in the database.
  16. The names of those actors/actresses who had more than one role in the same movie (like Robin Williams in Mrs. Doubtfire).
  17. 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.

  1. Create a new table that contains two columns with the first being a director_id and the second being an average rank rating.
  2. Populate your table by using insert command(s) and the tables already in the database.
  3. 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!