Subject Re: [ib-support] FW: newbie ?s - trigger problem revisited
Author Lucas Franzen
Jon-David,

Given your trigger-code is copied correcty there are some mistakes:


> Trigger: PRODUCT_INSERT
>
> CREATE TRIGGER PRODUCT INSERT

should read:
CREATE TRIGGER PRODUCT_INSERT FOR ???TABLE???



> ACTIVE
> AFTER INSERT
> AS
> BEGIN
> INSERT INTO TRANSACTION1

?? What is TRANSACTION1 - you didn't show the DDL of that table.

> ( TID, TRANS_TYPE, EDITOR)
> VALUES
> ('1', 'insert', 'dude');

if you want to use generators, replace it with:

VALUES
( GEN_ID ( <GENERATOR_NAME>, 1), 'insert', 'dude');

> END;

I don't know about IBWorkbench and if it adds terminators on its own,
but there's one problem with the ";" sign.
You need it to terminate statements, thus you can't use it for
terminating the trigger itself.
Therefore there's the SET TERM statement.

So, your trigger should look like:

SET TERM #; /* make '#' the new ternmination sign */
CREATE TRIGGER PRODUCT_INSERT FOR <TABLE>
ACTIVE
POSITION 0
AFTER INSERT
AS
BEGIN
INSERT INTO TRANSACTION1
( TID, TRANS_TYPE, EDITOR)
VALUES
(GEN_ID ( <GENERATOR_NAME>, 1), 'insert', 'dude');
END #

SET TERM ;#

> I added the create, active, after insert, and AS since in workbench they are
> not coded into the editor but set as options.

ACTIVE is a default value.

If you CREATE a trigger you must specify:
- the triggername
- the table it is for
optionally you can specify:
- the position of the trigger (if you've got several triggers for the
same table and action but without / or with the same position number
they fitre in random order)
- ACTIVE/INACTIVE (where ACTIVE is default)


Hth
Luc.