Sei sulla pagina 1di 17

Homework 1 Solution

Discussion Session 3

Question 1
Consider the following ER Diagram, which associates actors and movies.

Which of the following statements are true?

EECS 484

Question 1
Consider the following ER Diagram, which associates actors and movies.

Which of the following statements are true? a)An actor can star in only 1 movie. False. There is no key constraint between Actor and Stars b)Each actor has to star in a movie. False. There is no participation constraint between Actor and Stars

EECS 484

Question 1
Consider the following ER Diagram, which associates actors and movies.

Which of the following statements are true? c) Every movie has an actor. True. There is a participation constraint between Movie and Stars 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.

EECS 484

Question 1
Consider the following ER Diagram, which associates actors and movies.

Which of the following statements are true? 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. f) Any two movies must have different names. False. The name of a movie is not unique nor a primary key
EECS 484

Question 2(a)
a) Can we create a greatest hits album containing most successful songs from past albums. Why or why not? 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.

EECS 484

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? 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.
EECS 484

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? 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
EECS 484

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?
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).
9

EECS 484

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.

EECS 484

10

Question 3 Solution(1)

EECS 484

Question 3 Solution(2)

Alternate solution: Aggregation with Orders separate entity and total bill as an attribute
EECS 484

12

Question 4
Consider a relation R with attributes A, B, and C. Suppose that you are given the following relation:
Which of the following attribute sets can you conclude are not keys for R? Briefly, justify your answer. A; B; C; BC; and AC
A 1 2 3 4 5 B 20 30 15 45 20 C x y z w z

EECS 484

13

Question 4 Solution
A 1 2 3 4 5 B 20 30 15 45 20 C x y z w z

Key: Minimal subset of attributes such that they are unique identifier for a tuple in all possible instances. 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.
EECS 484

14

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.

EECS 484

15

Question 5 Solution
Translation 1: Manager(name, salary); Employee(id, salary); Manages(manager_name,employee_id) CREATE TABLE Manager (name CHAR(20), salary INTEGER, PRIMARY KEY(name)); 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);

EECS 484

16

Question 5 Solution
Translation 2: Manager(name, salary);

Manages_Employee(employee_id, salary, manager_name) An assertion must be made to enforce the participation constraint, he/she should get full credit CREATE TABLE Manager (name CHAR(20), salary INTEGER, PRIMARY KEY(name)); 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);
EECS 484

17

Potrebbero piacerti anche