There is no need to create a history / audit table for each of them. You may have a single table that stores the table name and fields for the fields that you want to track:
audit(audit_id, table_name, field_name, action_flg, updated_by, updated_on, val_before, val_after, pk_value1, pk_value2, pk_value3, pk_value4, pk_value5) .
You need to save the primary key (fields pk_value1 to pk_value5 ) of the table to uniquely identify the row that was changed. action_flg used if you want to keep track of updates, inserts or lines that have been deleted. Oracle uses this table structure in some of its products.
For example, suppose you have a person(person_id, name, email) table person(person_id, name, email) , and you need to track the changes made to the email field:
A new person is created ( id=1 ): insert into audit(1, 'person', 'email', 'A' /* add */, 'USER', '11-03-2011', null, ' email@mail.com ', 1, null, null, null, null);
Updated person 1 email: insert into audit(2, 'person', 'email', 'C' /* change */, 'USER', '12-03-2011', ' email@mail.com ', ' new_email@mail.com ', 1, null, null, null, null);
Now suppose that person 70 email has been updated: insert into audit(3, 'person', 'email', 'C' , 'USER', '12-03-2011', ' p70email@mail.com ', ' new_p70mail@mail.com ', 70, null, null, null, null);
source share