This question has been answered on SO several times : here, here and external links here and here.
I understand the approaches described in above threads and I plan to use this approach.
But I've got few basic doubts in implementing that.
In my case, multiple columns in a row could be updated at the same time, so is following the correct way to implement:
At the basic database level you can track changes by having a separate table that gets an entry added to it via triggers on INSERT/UPDATE/DELETE statements. Thats the general way of tracking changes to a database table. The other thing you want is to know which user made the change.
Creating auditing columnsEvery time a row is added or changed in a table that has an auditing column, the value of the audit column is generated by the database manager. These generated values are maintained for both SQL and native changes to the row.
Assuming you are using a sufficiently recent version of mySQL I would use triggers, personally.
Assuming they work more or less as the ones I am familiar with in other products (e.g. Oracle) your problem becomes simpler, in the sense that you put an "update" triggers on the row and use it to update the audit table for each field you are interested in.
Possible caveat: if your application logs on the DB as just one user (a common approach if you use connection pooling, for example) it may be tricky to log the actual user identity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With