My system: Db2 11.1 on Linux.
1.Create some table:
create table admin.tab (a int not null primary key, b int) @
2.Create audit table:
create table admin.audit (table_name varchar(2000), datetime timestamp) @
3.Very very simple sample, when insert into source table admin.tab I would like to insert into admin.audit:
create trigger admin.mytrig
after insert on admin.tab
referencing new as new
for each row
begin
insert into admin.audit (table_name, datetime)
values ('admin.tab', current_timestamp);
end
@
4.Above trigger works fine, but is there any way in above trigger I can replace 'admin.tab' constant with current table name that was fired using trigger, like CURRENT_TABLE_TRIGGER_WAS_FIRED_ON
or something?
create trigger admin.mytrig
after insert on admin.tab
referencing new as new
for each row
begin
insert into admin.audit (table_name, datetime)
values (CURRENT_TABLE_TRIGGER_WAS_FIRED_ON, current_timestamp);
end
@
I need this kind of solution, because I need to create hundreds of such triggers and to share as much code as possible saves a lot of time.