I would like to write the changes made to all fields of the table to another table. This will be used to keep a history of all changes made to this table (table of main change tables).
What is the best way to do this in SQL Server 2005?
I am going to assume that the logic will be placed in some triggers.
How can I go through all the fields that test the change without hard coding all the fields?
As you can see from my questions, the sample code will be very important.
I noticed that SQL Server 2008 introduced a new Change Data Capture (CDC) feature. (Here is a good Channel9 video on CDC). This is similar to what we are looking for, except that we are using SQL Server 2005, we already have the layout of the log table in place, and also register the user who made the changes. Itβs also difficult for me to justify the record before and after the image of the whole record, when one field can change.
Our current log file structure has a column for the field name, old data, new data.
Thanks in advance for a nice day.
Updated 12/22/08: I did some more research and found these two answers on the Live QnA search
You can create a trigger for this. See How to check sql server data changes .
You can use triggers to record data changes in the log tables. You can also purchase the log explorer from www.lumigent.com and use it to read the transaction log to see what the user has done. However, the database must be fully restored for this option.
Updated 12/23/08:. I also need a clean way to compare what has changed, and it looks like the flip side of the PIVOT that I discovered in SQL is called UNPIVOT. Now I'm leaning towards a trigger using UNPIVOT in the INSERTED and DELETED tables. I was curious if this has already been done, so I am looking at a search for univot deleted insert .
sql sql-server tsql sql-server-2005
Gerhard weiss
source share