Consider the relational schema shown in Figure 26.18. Write active rules for keeping the SUM_COMMISSIONS attribute of SALES_PERSON equal to the sum of the COMMISSION attribute in SALES for each sales person. Your rules should also check if the SUM_COMMISSIONS exceeds 100000; if it does, call a procedure NOTIFY_MANAGER(S_ID). Write both statement-level rules in STARBURST notation and row-level rules in Oracle.

What will be an ideal response?


Oracle notation rules:
CREATE TRIGGER KEEP_EM_SAME
AFTER INSERT OR UPDATE OF COMMISION ON SALES
FOR EACH ROW
UPDATE SALES_PERSON
SET SUM_COMISSIONS = (SELECT SUM (COMISSION)
FROM SALES
WHERE S_ID = NEW.S_ID);
CREATE TRIGGER NOTIFY_MANAGEMENT
AFTER INSERT OR UPDATE OF SUM_COMISSIONS OF SALES_PERSON
FOR EACH ROW
WHEN ((SELECT SUM(COMISSION)
FROM SALES_PERSON
WHERE SALES_PERSON_ID = NEW.SALES_PERSON_ID) >
100000
NOTIFY_MANAGER(NEW.SALES_PERSON_ID);
Starburst notation rules:
CREATE RULE KEEP_EM_SAME ON SALES
WHEN INSERTED OR UPDATED(COMISSION)
THEN UPDATE SALES_PERSON AS S
SET S.SUM_COMISSIONS = ( SELECT SUM(COMISSIONS)
FROM SALES AS L
WHERE S.S_ID = L.S_ID)
WHERE S.SALESPERSON_ID IN ((SELECT S_ID FROM UPDATED)
OR (SELECT S_ID FROM INSERTED));
CREATE RULE NOTIFY_MANAGEMENT ON SALES_PERSON
WHEN INSERTED OR UPDATED(SUM_COMISSIONS)
THEN NOTIFY_MANAGER(SELECT SALESPERSON_ID
FROM SALES_PERSON AS S
WHERE S.SUM_COMISSIONS > 100000)
AND
S.SALESPERSON_ID IN
((SELECT SALESPERSON_ID FROM
UPDATED)
OR (SELECT SALESPERSON_ID FROM
INSERTED)));
We assumed that there would be no deletions of sales. If deletion of sales were a
possibility, we would simply enhance the above rules to accommodate the delete option as
well.

Computer Science & Information Technology

You might also like to view...

The ________ provides the area in which you type the URL for the site you want to visit, and which also works as a search box

A) address bar B) page tab C) menu button D) browsing window

Computer Science & Information Technology

The Convert Table to Text dialog box is used to convert an Access table to a delimited file

Indicate whether the statement is true or false

Computer Science & Information Technology

?Businesses started adopting Internet Explorer more than 20 years ago simply to view webpages. Today, Microsoft Edge has a different purpose: __________. 

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Solve the system of equations.

A.
B.
C.
D. Infinite number of solutions
E. No solution

Computer Science & Information Technology