




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





CS 311 Introduction to Database Management Systems Department of Computer Science University of Illinois at Urbana-Champaign
1. (20 points) ER and Translation to Relational Model:
a. [15 points] Create a relational schema that captures this E/R diagram. For every relation in your schema, specify the key of that relation. b. [5 points] What is the key for entity " Contract_Emps "? And what is the key for “Hourly_Emps”? Briefly explain your answer.
Solution
Employees (EmployID, Lot) Hourly_Emps (EmployID, Hours_worked, Hours_wages) Contract_Emps(EmployID, Contractid) Work-in (EmployID, CompID) Company (CompID, Name, Budget, CEO_EmployID, CEO_Contractid, Since)
b) Contract_Emp key: EmployID, Contractid Hourly_Emps key: EmployID
This is ER style translation of is-a relationship, so they borrow the key from the parent entity.
Decomposition 2: Decomposing on either A → C or C → A
R 1 = (AC) FD 1 = {A → C, C → A} This is in BCNF as A and C are the keys and hence LHSs of all FDs are superkeys.
R 2 = (ABDE) FD 2 = {AB → E} This is not in BCNF as the key is CDB and hence LHS of FD AB → E is not a superkey.
Decomposing R 2 on AB → E R 21 = (ABE) F 21 = {AB → E} This is in BCNF as AB is the key and the LHS of the only FD.
R 22 = (ABD) F 22 = {} This is in BCNF because there is no FD
Therefore the decomposed schema is R 1 = (AC) FD 1 = {A → C, C → A} R 21 = (ABE) F 21 = {AB → E} R 22 = (ABD) F 22 = {}
We see here that the final decomposed schema in both the decompositions comes out to be the same. This is just a coincidence and might not always be the case.
3. (20 points, 10 points each) Relational Algebra:
Consider a database schema with the following relations:
Student (ssn, name) Prof (ssn, name) Course (number, instructor-ssn, title, credits, room#) Enroll (student-ssn, course#) Room (number, capacity)
a. Write a relational algebra query that finds the names of all students who are enrolled in a class taught by “Jones”.
b. Write a relational algebra query that finds the names of all students who are NOT enrolled in two classes held in the same room.
SELECT S.name FROM Student S, Enroll E, Course C WHERE S.ssn = E.student-ssn AND E.course# = Course.number GROUP BY S.ssn, C.room# HAVING count(*) <> 2
5. (10 points) SQL Queries:
Consider the following schema:
Project (project-name, member-id, start-date, end-date, budget, dept-id) Department(id, head ) Employee(employee-id, employee-name, department-id)
where "head" means the id of the employee who is the head of a department.
Write a SQL query that finds the names of employees who are involved in projects in which their department head is not involved.
SELECT Employee.employee-name FROM Employee e1, Project p WHERE e1.employee-id = p1.member-id AND p1.project-name NOT IN (SELECT p.name FROM Project p, Department d WHERE p.member-id = d.head AND d.id = e1.department-id)
6. (10 points) Constraints and Triggers
Briefly discuss the tradeoffs among checks, assertions, and triggers.
Checks put a constraint on the value of a particular attribute or a tuple. The condition may use the name of the attribute, but any other relation or attribute name must be in a subquery. A check is checked only when a value for that attribute or a tuple is inserted or updated.
Assertions are database-schema elements, like relations or views. Condition may refer to any relation or attribute in the database schema. In principle, we must check every assertion after every modification to any relation of the database. A clever system can observe that only certain changes could cause a given assertion to be violated.
Attribute- and tuple-based checks have limited capabilities. Assertions are sufficiently general for most constraint applications, but they are hard to implement efficiently. A trigger allows the user to specify when the check occurs. Like an assertion, a trigger has a general-purpose condition and also can perform any sequence of SQL database modifications.