• Non ci sono risultati.

Politecnico di Torino Database Management Systems

N/A
N/A
Protected

Academic year: 2021

Condividi "Politecnico di Torino Database Management Systems"

Copied!
2
0
0

Testo completo

(1)

Politecnico di Torino

Database Management Systems

July 8

th

2011

Trigger exercise: draft solution

1. (7 Points) The following relations are given (primary keys are underlined, optional attributes are denoted with *):

PERSON (RegNumber, Job)

SHIFT (RegNumber, Date, TCode)

SHIFT-TYPE (TCode, StartTime, Duration) LEAVE-REQUEST(RCode, RegNumber, Date)

NOTIFICATION(RegNumber, Date, RequestOutcome)

Write a trigger to manage one-day leave requests by people working in a hospital (insert into the LEAVE-REQUEST table). A leave request is accepted if the person requesting it is not on duty in the requested date (SHIFT table). If instead the person is on duty, the request is accepted only if another person is available to fill the requester’s shift. Otherwise, the request is declined. A person may substitute another person on a shift if they both have the same job and the substitute is not on duty in the same date.

The outcome of the request (accepted or declined) must be notified by means of an insert into the NOTIFICATION table.

EVENT: insert on LEAVE-REQUEST

EXECUTION GRANULARITY: row level (one request at a time) EXECUTION MODE: after (business rule)

CONDITION: NO ACTION:

(1) check if the person has the shift on the requested date

(2) if the person does not have the shift the request is accepted (3) if the person has the shift, check if there is another person

with the same job but no shift on the requested date

(4) if a person is available the request is accepted, otherwise the request is declined

(5) Notify the outcome of the request

create or replace trigger LeaveRequest after insert on LEAVE-REQUEST

for each row declare N number;

outcome varchar[20];

begin

--check if the person has the shift on the requested date select count(*) into N

from Shift

where RegNumber= :new.RegNumber and Date = :new.Date;

(2)

if (N=0) then

---The person does not have the shift outcome = ’accept’;

else

---The person has the shift. Check if there is another person with the same job ---but no shift on requested date

select count(*) into N from Person

where Job = (select Job from Person

where RegNumber = :new.RegNumber) and RegNumber not in

(select RegNumber from Shift

where Date = :new.Date);

if (N > 0) then

outcome = ’accept’;

else

outcome = ’reject’;

endif;

endif;

----Notify the outcome of the request

insert into Notification (RegNumber, Date, RequestOutcome) values (:new.RegNumber,:new.Date,outcome);

end;

2

Riferimenti

Documenti correlati

Temperature Programmed Surface Reaction experiments using ammonia well agree with the catalytic activity results, indicating that high H 2 and N 2 desorption are obtained only if

Previous studies 166 demonsti·ated that mechanisms responsible to resistance includes specific mutations within blaKPc 167 gene and that emerged after ceftazidime/avibactam

The former consisted in the absolute phase measurement of a voltage, with respect to the cosine waveform with positive peak aligned with the PPS signal (see Fig. The

The collected data included contrast bolus direction when arterial and portal phases were available (performed through the evaluation of the attenuation in the cranial and

of the cases were diagnosed as indolent lymphoma, while the remaining were referable to nodular hyperplasia, either purely lymphoid or complex type. Notably, none of the dogs

However, in severe conditions of a combined high electric field and high temperature, the current flow exceeds a threshold where massive injected charges

Loos and Luzak (Loos and Luzak 2016) identified five categories of potentially unfair clauses often appearing in the terms of on-line services: (1) establishing jurisdiction for

In fact, all the empirical parts of the thesis have been done using aggregate data of the Euro Area, implying that the monetary policy suggestions derived may be helpful for