Home > database >  How to extract the data before and after modification, stored in a log in the table
How to extract the data before and after modification, stored in a log in the table

Time:10-18

I have a diary table record the students list all the changes of the log,
The log table structure is: the l_time l_user stu_no stu_name stu_a stu_b stu_c

Students structure: stu_no stu_name stu_a stu_b stu_c


Request: l_time l_user change_Field old_value new_values



The truth is that students have 50 + column in the table
What method?


CodePudding user response:

 

- learn about the function of the CDC

Open the CDC
-The EXECUTE SYS. SP_CDC_ENABLE_DB
The EXEC SYS. SP_CDC_ENABLE_TABLE 'DBO', 'students' @ ROLE_NAME=NULL, @ SUPPORTS_NET_CHANGES=0


- query operation log
SELECT SYS. FN_CDC_MAP_LSN_TO_TIME ([__ $START_LSN]) AS time,
CASE [__ $OPERATION]
1 THEN the WHEN 'delete'
THEN the WHEN 2 'new'
Before the WHEN 3 THEN 'change'
After the WHEN 4 THEN 'change'
END AS operation type,
*
The FROM CDC. DBO_students_CT

- if you don't need, close
The EXEC SYS. SP_CDC_DISABLE_TABLE 'DBO', 'students',' ALL '
The EXEC SYS. SP_CDC_DISABLE_DB


  • Related