I have a table named tdc
:
create table tdc(pk int primary key,val int)
I am trying to use change tracking
on it. Here's the script:
drop table tdc
create table tdc(pk int primary key,val int)
ALTER TABLE tdc
ENABLE CHANGE_TRACKING
WITH (TRACK_COLUMNS_UPDATED = ON)
insert tdc(pk,val) select 0,432
insert tdc(pk,val) select 1,507
insert tdc(pk,val) select 2,312
insert tdc(pk,val) select 4,432 union all select 5,634
update tdc set val=888 where pk in(0,2)
update tdc set val=777 where pk in(0,2)
declare @from bigint= (select CHANGE_TRACKING_MIN_VALID_VERSION(object_id('dbo.tdc')))
select * from CHANGETABLE(CHANGES tdc,@from)q
I get:
+====================+=============================+======================+====================+====================+====+
| SYS_CHANGE_VERSION | SYS_CHANGE_CREATION_VERSION | SYS_CHANGE_OPERATION | SYS_CHANGE_COLUMNS | SYS_CHANGE_CONTEXT | pk |
+====================+=============================+======================+====================+====================+====+
| 49 | 44 | I | NULL | NULL | 0 |
+--------------------+-----------------------------+----------------------+--------------------+--------------------+----+
| 45 | 45 | I | NULL | NULL | 1 |
+--------------------+-----------------------------+----------------------+--------------------+--------------------+----+
| 49 | 46 | I | NULL | NULL | 2 |
+--------------------+-----------------------------+----------------------+--------------------+--------------------+----+
| 47 | 47 | I | NULL | NULL | 4 |
+--------------------+-----------------------------+----------------------+--------------------+--------------------+----+
| 47 | 47 | I | NULL | NULL | 5 |
+--------------------+-----------------------------+----------------------+--------------------+--------------------+----+
Why is SYS_CHANGE_COLUMNS NULL for the update
operation corresponding to SYS_CHANGE_VERSION 49?
As you can deduce from the SYS_CHANGE_VERSION
, I have drop-created this table multiple times. It might be helpful to mention that I had also change data capture
enabled in this table. Interestingly enough, cdc works correctly.