I want to add an audit trail for our system so when any Add/Delete/Update operation happen i will log it, with the following info:-
the CRUD operation type. is it add, delete or update.
the record ID which have been modified.
Date and time.
Now i found two approaches to follow; either to have a single audit trail table with the following fields:-
- ID .such as 123445.
- CRUD_description. Such as Delete
- Record_ID. Such as Qaeop12771
- Date. Such as 1june2O13
Or to have two tables one for a lookup table for the CRUD operation such as
- CRUD_ID. such as 3.
- CRUD_Description.such as Delete.
And then the Audit trial will reference the above table:-
- ID. such as 123445.
- CRUD_ID (this will be a foreign key to the CRUD table) such as 3.
- Record_ID. Such as Qaeop12771
- Date. Such as 1june2O13
So which approach is better ??
Second question If i will follow the second approach . Then is it preferred to use the CRUD_ID inside my code for example if the oprration is delete i might have my code look like:-
Inset into audit_trail (ID, CRUD_ID, Record_ID, Date) values ( 123445, 3,12771,1june2O13) //CRUID 3 represents delete operation.
Best Regards