






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!







Mingsong Chen Wenjie Yuan
Name: UFID: Email Address:
Pledge (Must be signed according to UF Honor Code)
On my honor, I have neither given nor received unauthorized aid in doing this assignment.
_______________________________________________Signature
For scoring use only:
Maximum Received
Exercise 1 20
Exercise 2 20
Exercise 3 20
Exercise 4 20
Exercise 5 20
Total 100
Answer: A trigger is a procedure that is automatically invoked in response to a specified change to the database. The advantages of the trigger mechanism include the ability to perform an action based on the result of a query condition. The set of actions that can be taken is a superset of the actions that integrity constraints can take (i.e. report an error). Actions can include invoking new update, delete, or insert queries, perform data definition statements to create new tables or views, or alter security policies. Triggers can also be executed before or after a change is made to the database (that is, use old or new data). There are also disadvantages to triggers. These include the added complexity when trying to match database modifications to trigger events. Also, integrity constraints are incorporated into database performance optimization; it is more difficult for a database to perform automatic optimization with triggers. If database consistency is the primary goal, then integrity constraints offer the same power as triggers. Integrity constraints are often easier to understand than triggers.
Solution: Consider the set of FD: AB โ CD and B โ C. AB is obviously a key for this relation since AB
โ CD implies AB โ ABCD. It is a primary key since there are no smaller subsets of keys that hold over R(A,B,C,D). The FD: B โ C violates 2NF since:
Answer: Consider the set of FD: AB โ CD and C โ D. AB is obviously a key for this relation since AB โ CD implies AB โ ABCD. It is a primary key since there are no smaller subsets of keys that hold over R(A,B,C,D). The FD: C โ D violates 3NF but not 2NF since: D C is false; that is, it is not a trivial FD C is not a superkey D is not part of some key for R
i. (1) On insert triggers have no :OLD values (2) On delete triggers have no :NEW values.
Answer: (C)
ii. (1) If a transaction is rolled back, the data changed by the trigger cannot be rolled back. (2) Triggers do not commit transactions. Unhandled exceptions in the trigger will cause a rollback of the entire transaction, not just the trigger.
Answer: (B)
iii. (1) A commit/rollback affects the entire transaction, it is all or none. (2) Commits, rollbacks and save points are not allowed in the trigger body.
Answer: (A)
iv. (1) A trigger cannot cause other events to execute triggers. (2) A trigger can change a table that it has read from, using the :OLD and :NEW values.
Answer: (D)
v. (1) If more than one trigger is defined on an event, the order in which they fire is not defined. (2) If the triggers must fire in order, create one trigger that executes all the actions in the required order.
Answer: (C)
Given relation:
R= {A,B,C,G,H,I}
and a set F of functional dependencies:
(a) Determine the closure F+ of F (Note: Trivial dependencies do not have to be shown). Answer: F+ = {AโB, AโC, CGโH, CGโI, BโH, AโH, CGโHI, AGโI} *can also include trivial dependencies, not shown for simplicity.
(b) Given a functional dependency X โ Z (where X, Z โ R).
Let us consider ABC joining ACDE = ABCDE. Common attributes between R1 and R2 are (AC). Since ( R 1 โฉ R 2) โ R 1 โ F +, hence R1 and R2 is lossless-join. Now consider ABCDE joining ADG = ABCDEG. The common attributes are AD. Since ADโR3โ F + (i.e., from F, AD โ E and E โ G => AD โ G =>AD โ ADG). So, decomposition is lossless-join
Answer:
CREATE ASSERTION managerAge CHECK ((SELECT E.age FROM Emp E, Dept D WHERE E.eid = D.managerid ) > 30 )
Since the constraint involves two relations, it is better to define it as an assertion, independent of any one relation, rather than as a check condition on the Dept relation. The limitation of the latter approach is that the condition is checked only when the Dept relation is being updated. However, since age is an attribute of the Emp relation, it is possible to update the age of a manager which violates the constraint. So the former approach is better since it checks for potential violation of the assertion whenever one of the relations is updated.
4: To write such statements, it is necessary to consider the constraints defined over the tables. We will ssume the following:
CREATE TABLE Emp ( eid INTEGER, ename CHAR(10), age INTEGER, salary REAL, PRIMARY KEY (eid) )
CREATE TABLE Works ( eid INTEGER, did INTEGER, pcttime INTEGER, PRIMARY KEY (eid, did), FOREIGN KEY (did) REFERENCES Dept, FOREIGN KEY (eid) REFERENCES Emp, ON DELETE CASCADE)
CREATE TABLE Dept ( did INTEGER, buget REAL, managerid INTEGER , PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp, ON DELETE SET NULL)
Now, we can define statements to delete employees who make more than one of their managers:
DELETE FROM Emp E WHERE E.eid IN ( SELECT W.eid FROM Work W, Emp E2, Dept D WHERE W.did = D.did AND D.managerid = E2.eid AND E.salary > E2.salary )