When a new column is added to the table configured to record change data (cdc), the capture instance table will not have a new column until cdc is disabled and enabled for the original table. This removes the existing instance of the instance.
I thought that I could copy the existing data to a temporary table and then copy back using the following SQL. However, other CDC metadata, such as cdc.change_tables.start_lsn, becomes invalid.
How to save capture instance history using the same capture instance name, if at all?
Thanks Rich
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC OFF
alter database ChangeDataCaptureTest set RESTRICTED_USER with ROLLBACK IMMEDIATE
go
alter table dbo.Table1 add value3 varchar(20) DEFAULT '' not null
select * into cdc.dbo_Table1_temp from cdc.dbo_Table1_CT
alter table cdc.dbo_Table1_temp add value3 varchar(20) DEFAULT NULL
exec sys.sp_cdc_disable_table
@source_schema='dbo',
@source_name='Table1',
@capture_instance='dbo_Table1'
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'Table1',
@role_name = NULL,
@supports_net_changes = 1,
@filegroup_name = N'ChangeDataCapture'
GO
Insert into cdc.dbo_Table1_CT
SELECT *
From cdc.dbo_Table1_temp
go
drop table cdc.dbo_Table1_temp
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC ON
alter database ChangeDataCaptureTest set MULTI_USER
go
insert into table1
values(12,'zz','g')
source
share