1. (3 points for each) a.

A Datalog query is safe when every variable that appears on the right appears in a non-negated, non-arithmetic body part. b. Inserts and Updates. c. Updates and Deletes. d. SELECT A.Aonly, A.common, B.Bonly FROM A,B WHERE A.common1 = B.common1 AND A.common2 = B.common2 AND ...

(where Aonly are the attributes of A not in B, Bonly are the attributes of B not in A, A.common are the attributes common to A and B - comprised of common1, common2, and so on). e. Preservation of MDs. f. None. g. Tuning the schema, Reformulating the query, and controlling the use of indices. h. True. i. True. j. Database systems. This question is for fun only (as in all my exams) and points are awarded irrespective of what you write.

book sellers.C}.B. book publishers. This latter schema is in 4NF (all MDs are trivial). Since the B->D FD is violating BCNF.D} and {A. so we are done. Book sellers has a one-many relationship to book stores. Books and authors are connected by a many-many relationship. Two subclasses inherit from book stores .brick and web-based. 3. There are at least two notes: (i) A book seller must have at least one book store. (ii) A book store can be brick or web-based but not both. First decompose the schema into BCNF before decomposition into 4NF. Book stores has a many-many relationship to book publishers. authors.count) AS SELECT name. There is a referential integrity constraint from books to book publishers.B. COUNT(*) FROM Students GROUP BY name. 4. This query is not impossible. CREATE VIEW Occurs(name.C}. The key is {A. we decompose the relation schema into {B. and book stores.books.2. There are five entity sets . . Books and book publishers are connected by a many-one relationship.

// first make a list of all As .GasStations(x._. remove it.y.r2). NOT CannotbeSecondHighest(x).r1). SecondHighest(x) <._.z.y. The following Datalog program mimics this idea. r1 < r2.z. "find the students who have taken ALL the courses required for graduation").SELECT name FROM Occurs WHERE count = (SELECT MAX(count) FROM Occurs)._). Ans(y) <. Similarly._. "find the customers who have rented ALL the DVD movies". CannotbeSecondHighest(x) <.._). r1 < r2.r1). find the As that pair up with ALL the Bs.GasStations(x.r2). We can first find the gas station with the highest revenue. CannotbeHighest(_. and find the station with the highest revenue (again). This problem is merely asking you to do the divide operation.CannotbeHighest(x.CannotbeHighest(x. GasStations(_. 6._.g.y.z. 5. SecondHighest(x). which we have seen in many homeworks (e. CannotbeHighest(x.y._._.r1) <._.

pi_ssn (Individuals) = {} or we can say pi_id (Students) <subset of> pi_ssn (individuals) In other words. The second part can be solved quite simply by: pi_id (Students) .Notpresent 7.. ..An} (Ideally ..A2.An} R // the list of Bs is given in S AllBs = S // ideally.. not the OR.. all the As occur with all the Bs Ideally = AllAs X AllBs // the reality is given by the relation R Reality = R // their difference identifies some As and the Bs they // don't occur with Notpresent = pi_{A1. so lets remove them! Ans = AllAs .Reality) // these must be the bad As.. The first part can be solved by: sigma_{gender <> 'M' AND gender <> 'F') Students = {} Notice that we need the AND here.AllAs = pi_{A1.A2.. the id field of *every* record in Students must map into the ssn of *some* record in Individuals..

8. Spring 2001 Final Solution Sketches ----------------------- 1. Horizontal partitioning. Ones which are joins. c. a. This problem is taken straight from the last homework. avoiding subquery blocks etc. but that entity *has to exist*. g. A referential integrity constraint is a stricter form of a -one constraint." The answer is NOT "to do this you need to use DISTINCT. pi_a (sigma_b (R times S)) . m+n b." f. The answer is NOT "because that is how they designed it. h. vertical partitioning. Because it is cheaper than checking every tuple to ensure there are no duplicates. controlling the use of indices. False. zero d. e. Not only can there be at most one entity connected by the -one relationship. i. decompositions. involve aggregates etc. Snap-together visualization: a way to rapidly prototype visualizations by connecting together information from database tables.

trying to solve it in one (or few) steps." 6. j. there is a course (b) that is required for graduation and that is taken by a. HasTaken(a.c). 2. The neatest solution I found is: Answer(a) <. Therefore {A. and there is a course (c) that is required for graduation and that is not taken by a. Impossible.E}}.b). RequiredForGraduation(c).where b = condition where attributes with similar names are matched up and a = list of attributes.E} is a key and the relation can be decomposed along the above FD to produce: {{B. the pitfall is (as I have said numerous times). i. Again. with duplicates removed. 4. Thus the diagram has to be pushed out and the arrow in the "passes through" relationship towards Cities has to be removed. This is the definition of "some but not all..RequiredForGraduation(b). . 3. Nobody seems to have got this right.B.A. Highways has to be an entity set.C.{B. NOT HasTaken(a. Opun. The relational algebra condition is just short for B->CD.e. 5.D}.

CommonAncestors(x. z is a common ancestor of x and y if z is an ancestor of x and z is an ancestor of y.First find Ancestors (this was demonstrated in class): Ancestor(x.y) <. CannotBeEarliest(x. if z is himself an ancestor of w who is also a common ancestor of x and y. .z).Ancestor(x.y. Ancestor(y.z). Find the CommonAncestors that cannot be earliest and subtract. z cannot be the earliest common ancestor (ECA) of x and y. The goal is to find the earliest.. Ancestor(z.z) <. ECA(x.Father(x. x<>y.w). In other words.y). Ancestor(w.y.y.z). But there could be many such CommonAncestors.Father(x.z) <. i. NOT CannotBeEarliest(x.CommonAncestors(x.z).y.z). find CommonAncestors: CommonAncestors(x.e.y.z).y) <.y.z) <. There is no way to do this in one step.z). Ancestor(x.y. Thus. CommonAncestors(x. Then.y). Partial credit is given for good attempts.

Spring 2000 Final Answer key and Grading Checklist ..7.battle.result FROM Outcomes.N. T2 AS T4 WHERE T3.date < T4. Call it Numbers.results) AS SELECT ship.. N AS Numbers. SELECT S.ship FROM T2 AS T3.battle = Battles.. . Battles WHERE Outcomes. CREATE VIEW T2(ship. 8.battle. SELECT T3. FROM S AS Numbers.result = "damaged". Again.battle (* "another" battle *) AND T3.date.ship (* ships are the same *) AND T3.battle <> T4. E AS Numbers.date.. WHERE 1000*S+100*E+10*E+D + 1000*M+100*O+10*R+E = 10000*M+1000*O+100*N+10*E+Y.ship = T4. Create a relation that has all numbers in it (0-9)..date (* "later") AND T3.name.E. very few people solved this problem.

that can serve as its key. Then FD AB->C holds if: (S Theta_Join_{c} R) = {} where c = (R.A AND R. nCf(n/2) where f() is either the floor or the ceiling operator.g.A = S.C) d. f.6.B and R.C <> S. g. Constraints and Triggers e.1 of your textbook. UNIONs) and no comparisons are necessary. do not require checking for membership (e. Let S = R. Any variable appearing on the right hand side of a query must appear in a non-negated. Because every object of a class is assigned a unique OID. See section 4.B = S. non-arithmetic clause. . Lossless Join Decomposition b.-------------------------------- Question 1 (30 points): Short Answer Questions ---------------------------------------------------------- a. Because operations on bags are easier to implement. c.

superkey i. Thus. Any number can be expressed as the sum of 1s. People who are good at knitting tend not to have the Y chromosome. . interesting. The answer is *not* beers and diapers. j. This is a hint for "pushing out" a relationship into an entity set. Using prescription as a relationship will cost you five points. Due to the constraint in the last sentence. The best answer I found was that it leaves the right hand to have a drink! :-) Question 2 (10 points): E/R Diagram ---------------------------------------------------------- Everything except the last two sentences talk about "prescribe" as a verb and then suddenly it becomes a noun. and Patients. More mistakes will have additional penalties. Drugs. the arrows entering Drugs and Patients have to be removed. since that is a useful. and non-obvious pattern. prescriptions is a connecting entity set which typically will have many-one relationships to Doctors.h.

Question 3 (10 points): Decompositions ---------------------------------------------------------- Only one person answered this question satisfactorily (Subhangan Venkatesan). To phrase it in the form the question asks for: A decomposition of R into S and T is a lossless-join decomposition if: S Intersection T -> S OR S Intersection T -> T either of the two holds.the intersection of the two decompositions must be X (the left side of the FD) . . S = {ABC}. we get {X.Y} on one side and {X.the right side of the FD must be on one side of the decomposition. in the second example.something} on the other. but . T={CDE}. In both cases. So. We know that both BCNF and 3NF provide lossless join decompositions. All that needs to be done is to examine closely how we do decompositions in both. As you can see. for a violating FD X->Y.

neither of C->ABC or C->CDE holds. In the expression . but this rule will not hold in general. Maximum = mn. This is not impossible. b. It will not hold if R.Advisor(Z.Advisor(X.X<>Z. Partial credit will be given for attempt. Answer(X) <. Question 4 (20 points): Queries and Misc. S and T are bags instead of sets.Student(X. A->ABC holds. so it is lossless. MultiAdvisor(Y) <. hence it is not lossless. c.Y). Question 5 (10 points): Monotonic Operators ---------------------------------------------------------- Only the difference operator is not monotone. This will occur when all tuples in R match all in S. NOT MultiAdvisor(Y).Y). Most of you got the first bullet right but extrapolated it to say that the intersection should be a key. In the first example. This will occur when no tuples match in R and S. It so happens in this case that A is a key.Y). ---------------------------------------------------------- a. Minimum = 0.

gpa AND S2. This is an exercise problem from the textbook. Student S3 WHERE S1.gpa . Ideally = . Reality = HasTaken BadStudents = Ideally . look at BadStudents and pick out the students who only occur once (i.Reality Now..e. are bad because of only one course).. This is easily done by finding students who occur two or more times and then subtracting them from BadStudents. Student S2.A-B. this is not impossible.. adding more tuples to B can actually make the answer smaller.name FROM Student S1. Here's a sketch. Question 6 (10 points): Relational Algebra ---------------------------------------------------------- Again.gpa = S2.gpa = S3. Question 7 (10 points): SQL ---------------------------------------------------------- SELECT S1.

id Leaving out the last AND will cost you three points.age < S3.age AND S1.age < S2. This problem is a solved one in the puzzles section on the course web page.age AND S2.id <> S3. . Question 8 (15 points): SQL ---------------------------------------------------------- Again.AND S1. this is not impossible.

Sign up to vote on this title
UsefulNot useful