Friday, December 10, 2021

Change tracking in SQL

 Open SSMS in administrator mode

Run the following command


ALTER DATABASE DATABASENAME

SET CHANGE_TRACKING = ON

(CHANGE_RETENTION = 5 DAYS, AUTO_CLEENUP = ON)




Enable change tracking on the particular table :

ALTER TABLE custgroup

ENABLE CHANGE_TRACKING

WITH (TRACK_COLUMNS_UPDATED = ON)




To view the change-tracking history of a particular table :

select * from CHANGETABLE(CHANGES custGroup, 0) AS ChTbl


Tada!!