Re: Trigger question.
Posted in 1996
Spetc wrote:
>
> Suppose you have a table with a date last modified column (datetime year
> to second.)
>
> This column would be stamped with the current date and time whenever a row
> is inserted or modified in the table.
>
> This would ideally be done via inserts and update triggers.
>
> Do anyone know how to use a trigger to intercept the insert or update and
> set this value prior to the insert / update operation?
Hi,
The problem here is that a triggered action cannot act on the
table that triggered it. AFAIK, you have two options:
1. Build the timestamp into the application so that it is processed
with the rest of the row. (PERFORM, 4GL, SQL insert/update statement)
2. Build a separate table:
create table audit_tab (tabname char(20), primary_key integer,last_mod datetime);
Then your insert trigger can insert a new row into audit_tab, and
your
update trigger can update the appropriate row into audit_tab.
NB Option 2 will hit performance in a large database, as all update and
insert processes will compete for the same table.
HTH,
Richard.