Subject | Re: [ib-support] FW: newbie ?s - trigger problem revisited |
---|---|
Author | Lucas Franzen |
Post date | 2002-02-19T18:57:15Z |
Jon-David,
Given your trigger-code is copied correcty there are some mistakes:
CREATE TRIGGER PRODUCT_INSERT FOR ???TABLE???
VALUES
( GEN_ID ( <GENERATOR_NAME>, 1), 'insert', 'dude');
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 ;#
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.
Given your trigger-code is copied correcty there are some mistakes:
> Trigger: PRODUCT_INSERTshould read:
>
> CREATE TRIGGER PRODUCT INSERT
CREATE TRIGGER PRODUCT_INSERT FOR ???TABLE???
> ACTIVE?? What is TRANSACTION1 - you didn't show the DDL of that table.
> AFTER INSERT
> AS
> BEGIN
> INSERT INTO TRANSACTION1
> ( TID, TRANS_TYPE, EDITOR)if you want to use generators, replace it with:
> VALUES
> ('1', 'insert', 'dude');
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 areACTIVE is a default value.
> not coded into the editor but set as options.
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.