Databases EECS 484 HW1 soln

Download Databases EECS 484 HW1 soln

Post on 27-Oct-2015

104 views

Category:

Documents

6 download

Embed Size (px)

DESCRIPTION

Solution to eece 484 HW 1

TRANSCRIPT

<ul><li><p>Homework 1 SolutionDiscussion Session 3</p><p>EECS 484</p><p>Question 1*Which of the following statements are true?Consider the following ER Diagram, which associates actors and movies.</p><p>EECS 484</p><p>Question 1*Which of the following statements are true?</p><p>a)An actor can star in only 1 movie.False. There is no key constraint between Actor and Stars</p><p>b)Each actor has to star in a movie.False. There is no participation constraint between Actor and Stars</p><p>Consider the following ER Diagram, which associates actors and movies.</p><p>EECS 484</p><p>Question 1*Which of the following statements are true?</p><p>c) Every movie has an actor.True. There is a participation constraint between Movie and Stars</p><p>d) A movie can have no more than one actor with a particular name.True. In this diagram, a movie can only have 1 actor to begin with.</p><p>Consider the following ER Diagram, which associates actors and movies.</p><p>EECS 484</p><p>Question 1*Which of the following statements are true?</p><p>e) There can be multiple movies called Inception in the year 2010.True. The pair (name,year) is not unique nor a primary key for the Movie entity.</p><p>f) Any two movies must have different names. False. The name of a movie is not unique nor a primary key</p><p>Consider the following ER Diagram, which associates actors and movies.</p><p>EECS 484</p><p>Question 2(a)a) Can we create a greatest hits album containing most successful songs from past albums. Why or why not?</p><p>There is a key constraint on Songs in Appears relationship. We cannot have a song that appears in multiple albums. Hence, we cannot create a new "greatest hits" album with songs already present in other albums. </p><p>*</p><p>EECS 484</p><p>Question 2(b)b) Suppose that you have noticed that musicians often keep multiple addresses due to touring. Does this ER diagram allow musicians to have multiple addresses? Why or why not?</p><p>Yes, a musician can be associated with multiple instances of the home relationship set, each of which includes an address and one or more phone numbers.</p><p>*</p><p>EECS 484</p><p>Question 2(c)c) Suppose that you want to enforce the constraint that every musician must play an instrument. Does this ER diagram capture this constraint? If not, what do you need to do?</p><p>You need to draw a bold line from the "Musicians" entity set to the "Plays" relationship set, which indicates a participation constraint. That is, every Musician entity must participate in at least one Plays relationship</p><p>*</p><p>EECS 484</p><p>*Question 2(d)d) Suppose Jay-Z and Justin Timberlake, two different musicians, wanted to produce a combined album together. Does this ER diagram allow us to represent this situation? Why or why not? If not, what must be changed?</p><p>An album can only be produced by 1 Musician therefore a combined album would not be possible according to this diagram. If there was not a key constraint on Album to Produces, then it would be possible (change the bold arrow to just a bold line).</p><p>*</p><p>EECS 484</p><p>Question 3*Your Great Uncle Rahul has hired you to improve the data management practices of his restaurant. Use an ER diagram to depict the following requirements.The restaurant employs a number of chefs. For each chef, you must keep track of the chefs name, address, phone number, rating, and salary. (Do not assume that chef names are unique.)Each chef must be able to prepare one entre at the minimum, and you must record the name of each entre, as well as its price. Two entres cannot have the same name. Each entre contains several ingredients. The name of the ingredient, as well as the quantity required for that particular entre, should be recorded. Every ingredient belongs to some entre.Each entre must be prepared by some chef and must contain some ingredient.Entres are ordered by customers. Each customer has a unique ID. A record is kept of each customers name, address, total bill, and phone number. You must also record the time and date when each entre was ordered. </p><p>EECS 484</p><p>Question 3 Solution(1)</p><p>EECS 484</p><p>Question 3 Solution(2)*Alternate solution: Aggregation with Orders separate entity and total bill as an attribute</p><p>EECS 484</p><p>Question 4*Consider a relation R with attributes A, B, and C. Suppose that you are given the following relation:</p><p>Which of the following attribute sets can you conclude are not keys for R? Briefly, justify your answer.</p><p>A; B; C; BC; and AC</p><p>ABC120x230y315z445w520z</p><p>EECS 484</p><p>Question 4 Solution*Key: Minimal subset of attributes such that they are unique identifier for a tuple in all possible instances. </p><p>A candidate key satisfies the following:1) Two distinct tuples in any legal instance cannot have identical values in all fields of a key. 2) No subset of the set of fields in a key is a unique identifier for a tuple.In this case, we know B and C are not unique. Also a subset of AC, A, is a unique identifier. Therefore B,C,and AC are not keys. </p><p>ABC120x230y315z445w520z</p><p>EECS 484</p><p>Question 5*Consider the following ER Diagram, which associates managers and employees. Describe two reasonable translations to relational tables. For each translation, provide the appropriate DDL (i.e., CREATE TABLE) statements. </p><p>EECS 484</p><p>Question 5 Solution*</p><p>Translation 1: Manager(name, salary); Employee(id, salary); Manages(manager_name,employee_id)</p><p>CREATE TABLE Manager (name CHAR(20), salary INTEGER, PRIMARY KEY(name));</p><p>CREATE TABLE Employee (id INTEGER, salary INTEGER, PRIMARY KEY(id));CREATE TABLE Manages(employee_id INTEGER, manager_name CHAR(20) NOT NULL, PRIMARY KEY(employee_id), FOREIGN KEY(employee_id) REFERENCES Employee, FOREIGN KEY(manager_name) REFERENCES Manager);</p><p>EECS 484</p><p>Question 5 Solution*</p><p>Translation 2: Manager(name, salary); Manages_Employee(employee_id, salary, manager_name)</p><p>An assertion must be made to enforce the participation constraint, he/she should get full credit</p><p>CREATE TABLE Manager (name CHAR(20), salary INTEGER, PRIMARY KEY(name));</p><p>CREATE TABLE Manages_Employee(employee_id INTEGER, manager_name CHAR(20) NOT NULL, salary INTEGER, PRIMARY KEY(employee_id), FOREIGN KEY(manager_name) REFERNCES Manager);</p><p>*</p></li></ul>