Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Change Data Capture: Preserve capture instance data when a..

 
   Database Help (Home) -> Server RSS
Next:  How to overcome the AdsDsoObject, ADSI 5000 row l..  
Author Message
Richard Collette

External


Since: Apr 16, 2010
Posts: 1



(Msg. 1) Posted: Fri Apr 16, 2010 10:20 am
Post subject: Change Data Capture: Preserve capture instance data when adding co
Archived from groups: microsoft>public>sqlserver>server (more info?)

When a new column is added to table that is configured for change data
capture (cdc), the capture instance table will not have the new column until
cdc is disabled and re-enabled for the source table. In the process the
existing capture instance is dropped.

I thought I could copy existing data out to a temp table and then copy back
using the following SQL. However, other CDC meta information, such as the
cdc.change_tables.start_lsn, becomes invalid.

How can the capture instance history be preserved, using the same capture
instance name, if at all?

Thanks,
Rich

/*Change Data Capture Test - Alter table definition test */

/*Enter restricted mode so we don't lose data changes during this
process*/
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC OFF
alter database ChangeDataCaptureTest set RESTRICTED_USER with ROLLBACK
IMMEDIATE
go

/*Add a column to the table*/
alter table dbo.Table1 add value3 varchar(20) DEFAULT '' not null

/*Copy the existing change tracking into a temp table*/
select * into cdc.dbo_Table1_temp from cdc.dbo_Table1_CT

/*Add the new column to the temp table so that we don't have to map
all columns when we copy back, note that we use NULL as the default*/
alter table cdc.dbo_Table1_temp add value3 varchar(20) DEFAULT NULL

/*Disable CDC on the source table, this will drop the associated cdc
table*/
exec sys.sp_cdc_disable_table
@source_schema='dbo',
@source_name='Table1',
@capture_instance='dbo_Table1'

/*Enable CDC for the table which recreates the CDC table*/
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 values from the temp table back into the new CDC Table*/
Insert into cdc.dbo_Table1_CT
SELECT *
From cdc.dbo_Table1_temp
go

/*Drop the temp table*/
drop table cdc.dbo_Table1_temp

/*Go back into multi-user mode*/
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC ON
alter database ChangeDataCaptureTest set MULTI_USER
go

/*Add a new row to the table*/
insert into table1
values(12,'zz','g')

 >> Stay informed about: Change Data Capture: Preserve capture instance data when a.. 
Back to top
Login to vote
r mullen

External


Since: Apr 21, 2010
Posts: 1



(Msg. 2) Posted: Wed Apr 21, 2010 7:25 am
Post subject: Retaining CDC History [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I have no solution to this..but I was wondering if you ever came up with a solution. I have read in a few places that you need to make a second capture instance for the table. Then you will have the history in one table and the new history in the new capture instance table that you create. The first capture instance will eventually be cleared out whenever the "garbage collector" deletes the information for the set time you have it to delete information.

The problem with this is that if you have to add another column to the table while the first capture instance still has data in it. How do you retain that information without running into the problem that you ran into with preserving the lsn's?

Also, do you know how to make a second capture instance of the table? I've been struggling with that and have come up with no solutions so far?

Thanks so much and hope this helps out a little Smile



Richard Collette wrote:

Change Data Capture: Preserve capture instance data when adding co
16-Apr-10

When a new column is added to table that is configured for change data
capture (cdc), the capture instance table will not have the new column until
cdc is disabled and re-enabled for the source table. In the process the
existing capture instance is dropped.

I thought I could copy existing data out to a temp table and then copy back
using the following SQL. However, other CDC meta information, such as the
cdc.change_tables.start_lsn, becomes invalid.

How can the capture instance history be preserved, using the same capture
instance name, if at all?

Thanks,
Rich

/*Change Data Capture Test - Alter table definition test */

/*Enter restricted mode so we do not lose data changes during this
process*/
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC OFF
alter database ChangeDataCaptureTest set RESTRICTED_USER with ROLLBACK
IMMEDIATE
go

/*Add a column to the table*/
alter table dbo.Table1 add value3 varchar(20) DEFAULT '' not null

/*Copy the existing change tracking into a temp table*/
select * into cdc.dbo_Table1_temp from cdc.dbo_Table1_CT

/*Add the new column to the temp table so that we do not have to map
all columns when we copy back, note that we use NULL as the default*/
alter table cdc.dbo_Table1_temp add value3 varchar(20) DEFAULT NULL

/*Disable CDC on the source table, this will drop the associated cdc
table*/
exec sys.sp_cdc_disable_table
@source_schema='dbo',
@source_name='Table1',
@capture_instance='dbo_Table1'

/*Enable CDC for the table which recreates the CDC table*/
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 values from the temp table back into the new CDC Table*/
Insert into cdc.dbo_Table1_CT
SELECT *
From cdc.dbo_Table1_temp
go

/*Drop the temp table*/
drop table cdc.dbo_Table1_temp

/*Go back into multi-user mode*/
alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC ON
alter database ChangeDataCaptureTest set MULTI_USER
go

/*Add a new row to the table*/
insert into table1
values(12,'zz','g')

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Book Review: C# 4.0 In a Nutshell [O'Reilly]
http://www.eggheadcafe.com/tutorials/aspnet/6dc05c04-c7f9-40cc-a2da-88...2e6d891

 >> Stay informed about: Change Data Capture: Preserve capture instance data when a.. 
Back to top
Login to vote
Paul Weiss

External


Since: Jan 18, 2011
Posts: 1



(Msg. 3) Posted: Tue Jan 18, 2011 1:25 pm
Post subject: Re: Change Data Capture: Preserve capture instance data when adding co [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I think you need to just add one more step so that you can continue to get old historic changes from the CDC table:
update cdc.change_tables
set start_lsn = (select MIN(__$start_lsn) from cdc.dbo_Table1_temp)
where capture_instance = 'dbo_Table1';

This is something I've only tested a little bit and as of now I'm not allowed by our DBA to do this in our production environment because altering system table data is not recommended by Microsoft. Hopefully it helps and you can make use of it.

> On Friday, April 16, 2010 1:20 PM Richard Collette wrote:

> When a new column is added to table that is configured for change data
> capture (cdc), the capture instance table will not have the new column until
> cdc is disabled and re-enabled for the source table. In the process the
> existing capture instance is dropped.
>
> I thought I could copy existing data out to a temp table and then copy back
> using the following SQL. However, other CDC meta information, such as the
> cdc.change_tables.start_lsn, becomes invalid.
>
> How can the capture instance history be preserved, using the same capture
> instance name, if at all?
>
> Thanks,
> Rich
>
> /*Change Data Capture Test - Alter table definition test */
>
> /*Enter restricted mode so we do not lose data changes during this
> process*/
> alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC OFF
> alter database ChangeDataCaptureTest set RESTRICTED_USER with ROLLBACK
> IMMEDIATE
> go
>
> /*Add a column to the table*/
> alter table dbo.Table1 add value3 varchar(20) DEFAULT '' not null
>
> /*Copy the existing change tracking into a temp table*/
> select * into cdc.dbo_Table1_temp from cdc.dbo_Table1_CT
>
> /*Add the new column to the temp table so that we do not have to map
> all columns when we copy back, note that we use NULL as the default*/
> alter table cdc.dbo_Table1_temp add value3 varchar(20) DEFAULT NULL
>
> /*Disable CDC on the source table, this will drop the associated cdc
> table*/
> exec sys.sp_cdc_disable_table
> @source_schema='dbo',
> @source_name='Table1',
> @capture_instance='dbo_Table1'
>
> /*Enable CDC for the table which recreates the CDC table*/
> 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 values from the temp table back into the new CDC Table*/
> Insert into cdc.dbo_Table1_CT
> SELECT *
> From cdc.dbo_Table1_temp
> go
>
> /*Drop the temp table*/
> drop table cdc.dbo_Table1_temp
>
> /*Go back into multi-user mode*/
> alter database ChangeDataCaptureTest set AUTO_UPDATE_STATISTICS_ASYNC ON
> alter database ChangeDataCaptureTest set MULTI_USER
> go
>
> /*Add a new row to the table*/
> insert into table1
> values(12,'zz','g')


>> On Wednesday, April 21, 2010 10:25 AM r mullen wrote:

>> I have no solution to this..but I was wondering if you ever came up with a solution. I have read in a few places that you need to make a second capture instance for the table. Then you will have the history in one table and the new history in the new capture instance table that you create. The first capture instance will eventually be cleared out whenever the "garbage collector" deletes the information for the set time you have it to delete information.
>>
>>
>>
>> The problem with this is that if you have to add another column to the table while the first capture instance still has data in it. How do you retain that information without running into the problem that you ran into with preserving the lsn's?
>>
>>
>>
>> Also, do you know how to make a second capture instance of the table? I've been struggling with that and have come up with no solutions so far?
>>
>>
>>
>> Thanks so much and hope this helps out a little Smile


>> Submitted via EggHeadCafe
>> Twitter Search API with jQuery and JSONP
>> http://www.eggheadcafe.com/tutorials/aspnet/94d7bda5-c477-4ff9-b71d-e2...fc70c24
 >> Stay informed about: Change Data Capture: Preserve capture instance data when a.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Analysis Services Change Data Folder - How do you change the data folder in analysis manager when analysis services is running on a 64-bit server? Problem is that analysis manager will not run on a 64-bit machine.

update test data to the live data - I created a SQL server 05 test database. Now I'd like to update its data to the live database. Can you please show me how to do that? Thank you for your help in advance.

Tidying data - I have a database table with >20,000 rows and >50 fields, ~45 of which are VARCHARS. The data in this database is populated from a fixed-width text file using a process that is outside of my control. However, this results in many of the fields...

what is the best way to store this data - I have about a thousand variable length arrays of numeric data that I need to store, some can be as small as 14 numbers others can be as large as 1500 numbers. In your opinion, what would be the best way to do that? I'm going to read them in as I need...

Transferring data only from SQL 6.5 to SQL 2000 - We are currently in a transition period between using SQL 6.5 and SQL 2000 databases. We have a SQL 6.5 database that contains user data and is being updated regularly as new users are added or details change. We also have a new application that needs to...
   Database Help (Home) -> Server All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]