sql - Identify Row as having changes excluding changes in certain columns -
within our business rules, need track when row designated being changed. table contains multiple columns designated non-relevant per our business purposes (such date entered field, timestamp, reviewed bit field, or received bit field). table has many columns , i'm trying find elegant way determine if of relevant fields have changed , record entry in auditing table (entering pk value of row - pk cannot edited). don't need know column changed (although nice down road).
i able accomplish through stored procedure, ugly sp using following syntax update (or statements shortened considerably post):
insert [tblsourcedatachange] (pkvalue) select d.pkvalue deleted d inner join inserted on d.pkvalue=i.pkvalue ( i.[f440] <> d.[f440] or i.[f445] <> d.[f445] or i.[f450] <> d.[f450])
i'm trying find generic way designated ignore fields , stored proc still work if added additional relevant fields table. non-relevant fields not change whereas relevant fields tend little more dynamic.
have @ change data capture. new feature in sql server 2008.
first enable cdc on database:
exec sys.sp_cdc_enable_db
then can enable on specific tables, , specify columns track:
exec sys.sp_cdc_enable_table @source_schema = 'dbo', @source_name = 'xxx', @supports_net_changes = 1, @role_name = null, @captured_column_list = n'xxx1,xxx2,xxx3'
this creates change table named cdc.dbo_xxx
. changes made records in table recorded in table.
Comments
Post a Comment