Subject Trigger Templates
Author Joseph Alba
(I don't know if this should be for Architecture or Priorities. Apologies of
Helen)

I noticed that there are several triggers that have exactly the same body,
but are for different tables.

I would like to propose templates (like that of C++).

Example:

/* Template Definition */
CREATE TEMPLATE TRIGGER INSERT_TIMESTAMP
BEFORE INSERT POSITION 5
AS
BEGIN
NEW.INSERT_BY=USER;
NEW.INSERT_TIME=CURRENT_TIMESTAMP;
END^

/* Instantiation */
CREATE TRIGGER ACCOUNTS_INSERT_TIMESTAMP FOR ACCOUNTS
FROM INSERT_TIMESTAMP;

CREATE TRIGGER ITEMS_INSERT_TIMESTAMP FOR PAYEE
FROM INSERT_TIMESTAMP;

/* MORE AMBITIOUS - Multiple Tables */
CREATE TRIGGER ACTUAL_INSERT_TIMESTAMP FOR ACCOUNTS, PAYEE, CUSTOMER,
GENERAL_LEDGER
FROM INSERT_TIMESTAMP;

-----------------------------
Also, Triggers can be the same code for different "events" like, Before
Update and Before Delete can share the same code.
so, I would like to propose that multiple "events" can be included to the
Trigger Header like


CREATE TRIGGER Minus_OldValues FOR ITEMS
BEFORE UPDATE
BEFORE DELETE
POSITION 10
AS
BEGIN
UPDATE HEADER H
SET TOTAL=TOTAL-OLD.AMOUNT
WHERE H.MASTER_ID=OLD.MASTER_ID;
END^

CREATE TRIGGER Add_NewValues FOR ITEMS
AFTER INSERT
AFTER UPDATE
POSITION 10
AS
BEGIN
UPDATE HEADER H
SET TOTAL=TOTAL+NEW.AMOUNT
WHERE H.MASTER_ID=NEW.MASTER_ID
END^

This way, I write only two triggers instead of four.