I am doing an Audit trail on a table say Customer Table
Customer c1=new Customer(){name="customer1" ,job="IT",city="USA"};
Say if i am doing an update on customer table and I am updating Customer City to CANADA
c1.city="CANADA";
So what i have to do is Audit this in a table like,
-
CustomerID 1
-
fieldname city
-
oldvalue USA
-
Newvalue CANADA
and so on…. whtever field is updated.
My Question is ,say I have more than Fields, How can I implement this?
How can I compare OLD RECORD WITH UPDATED RECORD TO CHECK WHICH FIELD IS CHANGED.HOW CAN I CAPTURE THOSE CHANGED FIELDS AND SAVE THEM IN AUDIT TABLE
I wouldn’t. Use a database trigger so that whenever an UPDATE is run on the table in question, the state of the row before the update is captured and put into an audit table.