I’ve searched a long time and don’t found an solution here yet. Also this question is a little bit subjectiv. But i really need a good solution for this task.
I have a table with Volumes, Security and much more informations.
This data are daily changed.
Now i need to keep this changes in a history.
What is the best Solution to do this?
Making a Second table with the same Structure and just insert the “old” data into this table?
Or just making an additional parameter with Status?
Making this server side with triggers?
Or programmatically with a LINQ procedure?
We chose separate tables as it will keep your primary table lean and faster. We also opted for triggers, reasoning that if you ever change the entry mechanism, you wouldn’t want to have to rewrite your auditing. Also it can capture accidental DBA side changes.
Since update is effectively a delete and then an insert, you can achieve what has been suggested with a single trigger- this is what we did.
Create a table exactly matching your existing table, but with some added columns:
AUDIT_GUID VARCHAR(40),
AUDIT_TIMESTAMP DATETIME,
AUDIT_ACTION VARCHAR(20)
Create an “AFTER INSERT,DELETE,UPDATE” Trigger using the following general pattern (simply add more columns where necessary).
If you want to find updates, they will be rows in the history table that have a delete & update with the same Audit_GUID value. The timestamp also allows you to check changes made at a certain time, and we’ve also added a currentuser to find the person to blame if necessary!