Using UNPIVOT with CDC Functions to get Updated Columns List
Microsoft introduced Change Data Capture (CDC) technology in SQL Server 2008. This technology captures DML (insert/update/delete) changes to a table. After CDC is enabled for a database and a given table, one can use cdc.fn_cdc_get_all_changes_ function to query changes made to the table. cdc.fn_cdc_get_all_changes_ function returns all columns from the table, even when only one column was updated. It also returns __$update_mask column which is a bit mask that shows which columns were updated, but still - the whole row is returned. When calling this function with "all_update_old" option it returns two records for each update: one with "before update" values and one with "after update" values. The challenge was to produce a "log" table with columns like this:
commit_time | column_name | old_value | new_value |
Share this
Previous story
← Exadata OEM Monitoring Plugins are Now Available
You May Also Like
These Related Stories
Oracle Data Pump Can't Import LONG Columns
Oracle Data Pump Can't Import LONG Columns
Oct 30, 2006
2
min read
Automation, PowerShell and Word Templates - let the technician do tech
Automation, PowerShell and Word Templates - let the technician do tech
Jul 27, 2017
4
min read
Datascape Episode 55: The State of Database Security in 2022
Datascape Episode 55: The State of Database Security in 2022
Apr 27, 2022
1
min read
No Comments Yet
Let us know what you think