Question

I have worked on several applications that saved XML data into a database. To date all of them simply overwrote the current XML contents with the new XML contents.

I would like to save the changes to the XML to the database but not overwrite what is currently in the DB.

Short of just creating new rows for changes and leaving the old rows intact, what other options could I use?

I've thought about just saving the differences as actual text differences, which does not always work for XML.

Am I nuts for even wanting this?

Was it helpful?

Solution

You may want to consider adding an audit table to sit beside your data table.

It would have only the columns you are interested in tracking the history of along with a datetime column (to record the date of change) and normally you want some user information as well (i.e. pull the logged in user from the connection or provide a user name in your insert/update).

Then create an Update trigger on your data table and insert new rows into your audit table from the deleted pseudo table. This will contain the data prior to an update if you are performing an update since an update is really a delete and an insert.

There is also this more general purpose solution that proposes to use SQL CLR to abstract away implementing a unique audit table and trigger for each data table you wish to audit: http://www.sqljunkies.ddj.com/Article/4CD01686-5178-490C-A90A-5AEEF5E35915.scuk

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top