creating a trigger
Posted in 2006
Topics: Triggers, Constraints & Referential Integrity
hi all!!
last question of this year....
I want to use a trigger. Purpose is to keep track of changes in a table.
create trigger TRIG1after update <field> on <table>
write something in a table
before the word after....he gives me a syntax error has occurred.....and I
don't know why???
can anybody help me?
thanks Danny
On Dec 29, 2006, at 10:17 AM, Danny De Koster wrote:
> hi all!!
>
> last question of this year....
>
> I want to use a trigger. Purpose is to keep track of changes in a
> table.
>
> create trigger TRIG1> after update <field> on <table>
> write something in a table
>
> before the word after....he gives me a syntax error has
> occurred.....and I
> don't know why???
Syntax is:
Create trigger TRIG1UPDATE <field> on <table>
AFTER (write something in a table);
>
> can anybody help me?
> thanks Danny
>
>
>
> _______________________________________________
> Informix-list mailing list
> Informix-list@iiug.org
> http://www.iiug.org/mailman/listinfo/informix-list
Danny De Koster wrote:
> hi all!!
>
> last question of this year....
>
> I want to use a trigger. Purpose is to keep track of changes in a table.
>
> create trigger TRIG1> after update <field> on <table>
> write something in a table
>
> before the word after....he gives me a syntax error has occurred.....and I
> don't know why???
>
> can anybody help me?
> thanks Danny
Did you RTFM? See the Guide to SQL Syntax manual.
CREATE TRIGGER trig1
UPDATE OF somefield ON sometable
AFTER INSERT INTO someothertable.....;
But that will only fire once per UPDATE statement and not per row and will
fire even if no rows are updated by the statement. If you want to audit
changes to every row updated then:
CREATE TRIGGER trig2
UPDATE OF somefield ON sometable
REFERENCING OLD AS orig
REFERENCING NEW AS chng
FOR EACH ROW (
INSERT INTO someothertable ...
);
Art S. Kagel
Art S. Kagel wrote:
> Danny De Koster wrote:
>
>> hi all!!
>>
>> last question of this year....
>>
>> I want to use a trigger. Purpose is to keep track of changes in a table.
>>
>> create trigger TRIG1>> after update <field> on <table>
>> write something in a table
>>
>> before the word after....he gives me a syntax error has
>> occurred.....and I don't know why???
>>
>> can anybody help me?
>> thanks Danny
>
>
> Did you RTFM? See the Guide to SQL Syntax manual.
>
> CREATE TRIGGER trig1
> UPDATE OF somefield ON sometable
> AFTER INSERT INTO someothertable.....;
OOPS forgot the parenthesis around the INSERT statement above.
Art S. Kagel
> But that will only fire once per UPDATE statement and not per row and
> will fire even if no rows are updated by the statement. If you want to
> audit changes to every row updated then:
>
> CREATE TRIGGER trig2
> UPDATE OF somefield ON sometable
> REFERENCING OLD AS orig
> REFERENCING NEW AS chng
> FOR EACH ROW (
> INSERT INTO someothertable ...
> );>
> Art S. Kagel
>