Re: insert trigger on table - SE7.2x
Posted in 1999
You do not specify the exact version, however, in 7.2x an insert trigger
CANNOT modify the inserted row. In 7.3x that rule is relaxed somewhat
with caviats. HOWEVER, you do not need the perform DEFAULT to maintain
this column, ALTER the table and add a DEFAULT constraint to the
insert_date column and the engine will maintain it:
ALTER TABLE mytable MODIFY insert_date date DEFAULT today;
If you also need to maintain this or another date column on update you CAN
have an UPDATE TRIGGER that updates the modify_date/time column whenever
the row is updated (actually you make that trigger effective for ALL
columns EXCEPT the update_date/time column so you can manually update that
column as needed).
Art S. Kagel
Peter Wuyts wrote:
>
> Database triggers are a nice feature; but why won't it work on a simple
> thing?
>
> I have a table and a perform that contains the fields of this table,
> I am trying to make an insert trigger that would fill one of the fields in
> the records of this table with the date the record was inserted.
>
> Then I get an error 747 which says:
>
> 747: Table or column matches object referenced in triggering statement.> This error is returned when a triggered SQL statement acts on the triggering
> table, or when both statements are updates, and the column that is updated
> in the triggered action is the same as the column that the triggering
> statement
> updates.
>
> Does this mean that I can no way put triggered actions on the SAME table as
> the one that undergoes the triggering actions?
>
> Anybody have a way around this?
>
> Regards,
> Peter Wuyts
>
> PS: I know when using performs you do not need a trigger to do this (put
> "noentry, noupdate, default=today, format=... " as attributes for the field
> that should contain the insert-date), problem is that for some tables
> records are inserted via ESQL/C-routines which means that I have to make
> modifications to all these files in stead of simply(?) creating some
> insert-triggers.