Skip to content

Instantly share code, notes, and snippets.

@joesavak
Created November 5, 2010 15:58
Show Gist options
  • Save joesavak/664350 to your computer and use it in GitHub Desktop.
Save joesavak/664350 to your computer and use it in GitHub Desktop.
Easy Audit Trails
create or replace trigger master_table_audit
after insert or update or delete on master_table
for each row
--
begin
if UPDATING then
insert into audit_table (
pk_uid
,edit_user
,edit_datetime
,trg_action
--additional audit columns
) values (
:new.pk_uid
,:new.edit_user
,sysdate
,'UPDATE'
--additional audit columns
);
elsif DELETING then
insert into audit_table (
edit_user
,edit_datetime
,pk_uid
,trg_action
--additional audit columns
) values (
:old.edit_user
,sysdate
,:old.pk_uid
,'DELETE'
--additional audit columns
);
else
insert into audit_table (
pk_uid
,edit_user
,edit_datetime
,trg_action
) values (
:new.pk_uid
,:new.edit_user
,sysdate
,'INSERT'
--additional audit columns
);
end if;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment