|
ravininave
Yak Posting Veteran
India
94 Posts |
Posted - 02/17/2013 : 19:45:18
|
I'm writing a trigger for DELETE,UPDATE. Actually I've to create a log in a table about updated fields with old and new data. In my table there are at least 30-40 fields. I've to fetch only updated field Name with old data and new data and store it like
AppID, FieldName, OldValue, NewValue
(Current I'm checking on each field with old and new value and Inserting in log table) Can anyone share some piece of code.? Thanx
VB6/ASP.NET ------------------------ http://www.nehasoftec.com |
|
|
James K
Flowing Fount of Yak Knowledge
1730 Posts |
Posted - 02/17/2013 : 20:32:23
|
You should be able to use the COLUMNS_UPDATED property from within the trigger. However, personally, I have not used it for couple of reasons. Seems to require somewhat complex logic (at least to my simple-minded way of thinking) that involves bit-patterns, the number of columns you have in the table etc. If you are interested, documentation and examples are here: http://msdn.microsoft.com/en-us/library/ms186329.aspx
Instead, I have always simply saved the old values (and/or the new values) in a table that has the same structure as the original table (plus possibly some additional auditing information columns). Doing it the way you are doing makes it easier to query for changes in some cases, but in some other cases, the simple-minded approach works well. And, you lose type-safety when you save auditing information the way you are storing it. |
Edited by - James K on 02/17/2013 20:36:31 |
 |
|