31.12.2014 Views

Solutions to Midterm Examination

Solutions to Midterm Examination

Solutions to Midterm Examination

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Therefore, we need <strong>to</strong> create triggers for all the above events.<br />

One trigger for INSERT and one for UPDATE on work are given below.<br />

CREATE TRIGGER no_hard_working_1<br />

BEFORE INSERT ON works<br />

FOR EACH ROW<br />

WHEN new.e_id NOT IN ( SELECT manager_id FROM dept )<br />

DECLARE <strong>to</strong>tal INT;<br />

BEGIN<br />

SELECT sum(pct_time) INTO <strong>to</strong>tal<br />

FROM works w<br />

WHERE w.e_id = new.e_id;<br />

IF (<strong>to</strong>tal > 100 - new.pct_time )<br />

THEN raise_application_error(-2000, ’working <strong>to</strong>o hard’);<br />

ELSE IF<br />

END<br />

CREATE TRIGGER no_hard_working_2<br />

BEFORE UPDATE ON works<br />

FOR EACH ROW<br />

WHEN new.e_id NOT IN ( SELECT manager_id FROM dept )<br />

DECLARE <strong>to</strong>tal INT;<br />

BEGIN<br />

SELECT sum(pct_time) INTO <strong>to</strong>tal<br />

FROM works w<br />

WHERE w.e_id = new.e_id;<br />

END<br />

IF (<strong>to</strong>tal > 100 - new.pct_time + old.pct_time )<br />

THEN raise_application_error(-2000, ’working <strong>to</strong>o hard’);<br />

ELSE IF<br />

5. Consider a relation schema with attributes R = ABCGW XY Z and the set of dependencies<br />

F = {XZ → ZY B, Y A → CG, C → W, B → G, XZ → G}.<br />

(a) Find a minimal cover for F.<br />

After right-reducing, we have<br />

XZ → B<br />

XZ → G<br />

XZ → Y<br />

Y A → C<br />

Y A → G<br />

C → W<br />

B → G<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!