Re: Process in which to log certain Inserts, Updates, and Deletes
Posted in 1998
Topics: Server Administration, Triggers, Constraints & Referential Integrity
I'm not sure if this is what you have in mind, but here is how I track changes to my table "TABLE1", using triggers to add records to the history table "hist_TABLE1". It seems to be working well. create table "isdba".TABLE1 ( col_A char(5) not null, col_B char(30) not null ); create trigger "isdba".ins_TABLE1 insert on "isdba".TABLE1 referencing new as post for each row ( insert into "isdba".hist_TABLE1 (action, col_A, col_B, usr_name, act_dt) values ('I', post.col_A, post.col_B, USER, CURRENT year to second) ); create trigger "isdba".del_TABLE1 delete on "isdba".TABLE1 referencing old as pre for each row ( insert into "isdba".hist_TABLE1 (action, col_A, col_B, usr_name, act_dt) values ('D', pre.col_A, pre.col_B, USER, CURRENT year to second) ); create trigger "isdba".upd_TABLE1 update on "isdba".TABLE1 referencing new as post for each row ( insert into "isdba".hist_TABLE1 (action, col_A, col_B, usr_name, act_dt) values ('U', post.col_A, post.col_B, USER, CURRENT year to second) ); create table "isdba".hist_TABLE1 ( action char(1), col_A char(5), col_B char(30), usr_name char(8), act_dt datetime year to second ); - Paul (not a spokesman)