Altering a Trigger Body

From InterBase

Go Up to Altering Triggers


When a trigger body is altered, the new body definition replaces the old definition. When used to change only a trigger body, ALTER TRIGGER need contain any header information other than the trigger’s name.

To make changes to a trigger body:

  1. Copy the original data definition file used to create the trigger. Alternatively, use isql -extract to extract a trigger from the database to a file.
  2. Edit the file, changing CREATE to ALTER, and delete all trigger header information after the trigger name and before the AS keyword.
  3. Change the trigger definition as desired. Retain whatever is still useful. The trigger body must remain syntactically and semantically complete.

For example, the following ALTER statement modifies the previously introduced trigger, SET_CUST_NO, to insert a row into the (assumed to be previously defined) table, NEW_CUSTOMERS, for each new customer.

Note:
This example assumes that you have a table named NEW_CUSTOMERS with a column cust_no.
ALTER TRIGGER SET_CUST_NO
BEFORE INSERT AS
BEGIN
new.cust_no = GEN_ID(CUST_NO_GEN, 1);
INSERT INTO NEW_CUSTOMERS(new.cust_no, TODAY)
END ;

Advance To: