Assignment 11 - Solutions
Assignment 11 - Solutions
Assignment 11 - Solutions
Final Assignment #11 Instructor: Richard Frank ([email protected]) TA: Ankit Gupta ([email protected])
Total Marks: 50 (5% of the Individual Assignments) Due Date: Dec 2, 14:30 (paper and/or via the Online Submission Server) Question 1) Please complete Exercise 2.2 from the book. It has 6 sub-questions [3 marks each]. The question is also below:
Exercise 2.2 A university database contains information about professors (identified by social security number, or SSN) and courses (identified by courseid). Professors teach courses; each of the following situations concerns the Teaches relationship set. For each situation, draw an ER diagram that describes it (assuming no further constraints hold). 1. Professors can teach the same course in several semesters, and each oering must be recorded.
2.
3.
Every professor teaches exactly one course (no more, no less), and every course must be taught by some professor.
Question 2) Create the SQL statements to create the tables required for Question 1.2 above (Every professor teaches exactly one course (no more, no less). [5 marks]
CREATE TABLE Professorteaches ( ssn CHAR(10), courseId INTEGER,
Page 1
Question 3) Assume your database is made up of the Customer, CustomerAddress, Address tables from AdventureWorks. These 3 tables are represented below as C, CA and A, respectively. Given the Given the Relational Algebra (RA):
a) What does it mean in English? [1 mark] Select all customers with last name Doe who have an address in Burnaby. Their address could be their home or work. Display the resulting first-name, address type and all their address information. b) Write the corresponding SQL code [2 marks]. SELECT C.Firstname, CA.AddressType, A.* FROM C, CA, A WHERE C.CustomerID = CA.CustomerID AND CA.AddressID = A.AddressID AND A.City = Burnaby AND C.LastName = Doe c) Write the RA that is more efficient (no need to include calculations)? [3 marks]
d) Write the SQL code corresponding to the efficient RA? [3 marks] SELECT C.Firstname, CA.AddressType, A.* FROM (Select FirstName, CustomerID FROM C WHERE LastName =Doe) AS C, CA, (SELECT * FROM A WHERE City =Burnaby) AS A WHERE C.CustomerID = CA.CustomerID AND CA.AddressID = A.AddressID
Question 4) Consider a relation R with five attributes ABCDE. You are given the following dependencies: A B, BC E, and ED A. 1. List all keys for R. [3 marks] Page 2