CS 4250: Database Management Systems

Spring 2015 - Homework 1

Due Feb. 25, 2015, at the beginning of class

This is an individual assignment. All work must be your own. You should not look at any other student's work (in whole or in part, on paper or on screen), nor allow anyone else to look at yours, during the course of this assignment.

Turn in as hardcopy or via email (MS Word or PDF or plain text only). Typed wherever possible.

When drawing ER diagrams, do not be subtle. Make bold lines significantly wider than non-bold lines, and draw your arrows large.

  1. Consider a database containing information about pets. Create entities and relationships as appropriate for each situation.

    Information that is true for all of the following ER diagrams: All (mammalian) pets have RFID tag IDs that uniquely identify them, and also names and colors.

    For each of the following situations, draw an ER diagram that describes it. Unless told to do otherwise, consider each situation independently.

    1. Pets have food bowls. Sometimes bowls are shared among pets; sometimes one pet has multiple bowls. Every food bowl has a color, a size, and a unique manufacturer's ID.
    2. Some pets are rabbits, and the database needs to store the minimum cage size for each rabbit. Some pets are dogs, and the database needs to store the favorite treat for each dog.
    3. Every pet collar belongs to exactly one pet. Pet collars are identified by tag number, and the database also keeps track of collar colors and patterns. (Some pets are fashionistas and have many collars.)
    4. Pets must have a water bowl or bowls. Bowls are identified by a unique manufacturer's ID, and also have a color and size.
    5. The database must keep track of pet photos. To be in the database, each photo must be of one pet in the database and have a timestamp. Timestamps are not unique, since two family members might photograph different family pets at the exact same time.

  2. Translate the following image into relations. Write the SQL statements to create those relations. Write English explanations of anything in the ER diagram that is not captured in your SQL. (Assume all data types are integers.)
  3. Suppose a database has the following three relations.
    Students (sid: integer, fname: string, lname: string, gpa: real)
    StudentsInClubs (studentId: integer, clubId: integer)
    Hobbies (hobbyid: integer, name: string, monthlyCost: integer, team: bit)
    Clubs (cid: integer, clubName: string, hobby: integer, numClubMembers: integer, started: date, dues: integer)
    (The "bit" data type stores 0 or 1. False or true. Booleans.) "hobby" in Clubs is a foreign key referencing "hobbyid" in Hobbies. "clubId" in StudentsInClubs is a foreign key referencing the primary key of Clubs; "studentId" in StudentsInClubs is a foreign key referencing the primary key of Students. The monthly cost of a hobby is not the same as the club dues. (One might pay dues to belong to a polo club, and also pay monthly costs to feed and stable one's polo ponies.)

    Write the following queries in relational algebra.

    1. Find the student ids, last names and GPAs of students that have the first name "Groot".
    2. Find the club names, dues and number of club members for clubs that started after 2 / 16 / 2014.
    3. Find the first and last names of students who belong to the club with clubID equal to 12.
    4. Find the first and last names of students who belong to the club named "Dragon Trainers".
    5. Find the club names and number of members of clubs that focus on a hobby which involves teams.
    6. Find the last and first names of students who belong to clubs where the club hobby costs more than $500 a month. (The rich kids!)