Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何将CDC表移动到新的文件组?_Sql Server_Sql Server 2008_Tsql_Cdc - Fatal编程技术网

Sql server 如何将CDC表移动到新的文件组?

Sql server 如何将CDC表移动到新的文件组?,sql-server,sql-server-2008,tsql,cdc,Sql Server,Sql Server 2008,Tsql,Cdc,我不熟悉SQL Server、复制和CDC的概念。我为CDC做了一些初级教程。我的问题是——因为CDC生成了如此多的数据,占用了如此多的空间(内存),我们需要提高它的效率。决定是将CDC表移动到新的文件组。以下是它的选项(所有选项都有可能破坏CDC): i) 在每个表上重新创建主键 ii)ALTERTABLE create语句 iii)将整个CDC架构移动到新的文件组 请建议/指导如何进行此操作 Regards, CD 在这里输入code好的,所以没有人回答我的问题..我等了一天,甚至没有评论

我不熟悉SQL Server、复制和CDC的概念。我为CDC做了一些初级教程。我的问题是——因为CDC生成了如此多的数据,占用了如此多的空间(内存),我们需要提高它的效率。决定是将CDC表移动到新的文件组。以下是它的选项(所有选项都有可能破坏CDC):

i) 在每个表上重新创建主键

ii)ALTERTABLE create语句

iii)将整个CDC架构移动到新的文件组

请建议/指导如何进行此操作

Regards,
CD

在这里输入code
好的,所以没有人回答我的问题..我等了一天,甚至没有评论。不管怎么说,我自己也在努力寻找答案,所以在这里,希望至少能得到一些选票P

2个逻辑选项:

1) 禁用CDC,然后启用CDC,同时更改文件组-现在这似乎合乎逻辑,但您会丢失所有以前的CDC数据,并且可能会丢失CDC元日期。尽管如此,这对某些人来说还是有用的,因此请查看以下内容:

Declare @RowNo Int, @RowCount Int, @Capture_Instance Varchar(200), @strSQL NVarchar(1000)
Set @RowCount = 0 
Set @RowNo = 1 
Set @Capture_Instance = ''
Set @strSQL = ''

Declare @myTable Table (Capture_instance Varchar(200), RowNo Int) 
Insert Into @myTable 
Select capture_instance, ROW_NUMBER() Over(Order By Source_Object_Id) As RN From cdc.change_tables 

Set @RowCount = @@ROWCOUNT 

While @RowNo <= @RowCount 
Begin 

Select @Capture_Instance = Capture_instance From @myTable Where RowNo = @RowNo 

Set @strSQL = 'sys.sp_cdc_disable_table @source_schema = N''' + Left(@Capture_Instance, CharIndex('_', @Capture_Instance) - 1)  + ''', 
    @source_name = N''' + SubString(@Capture_Instance, CharIndex('_', @Capture_Instance) + 1, Len(@Capture_Instance)) + ''',
    @capture_instance = N''All'''

Exec sp_ExecuteSQL @strSQL /*Diabling the sp_cdc*/

Set @strSQL = 'sys.sp_cdc_enable_table @source_schema = N''' + Left(@Capture_Instance, CharIndex('_', @Capture_Instance) - 1)  + '''
    ,@source_name = N''' + SubString(@Capture_Instance, CharIndex('_', @Capture_Instance) + 1, Len(@Capture_Instance)) + '''
    ,@role_name = N''' + 'cdc_Admin' + '''
    ,@fileGroup_Name = N''' + 'CDCFileGroup' + ''';'

Exec sp_ExecuteSQL @strSQL /*Enabling the sp_cdc, with a new CDCFileGroup(this filegroup would have been created before running this script)*/

Set @RowNo += 1 
End

在这里输入code
好的,所以没有人回答我的问题..我等了一天,甚至没有评论。不管怎么说,我自己也在努力寻找答案,所以在这里,希望至少能得到一些选票P

2个逻辑选项:

1) 禁用CDC,然后启用CDC,同时更改文件组-现在这似乎合乎逻辑,但您会丢失所有以前的CDC数据,并且可能会丢失CDC元日期。尽管如此,这对某些人来说还是有用的,因此请查看以下内容:

Declare @RowNo Int, @RowCount Int, @Capture_Instance Varchar(200), @strSQL NVarchar(1000)
Set @RowCount = 0 
Set @RowNo = 1 
Set @Capture_Instance = ''
Set @strSQL = ''

Declare @myTable Table (Capture_instance Varchar(200), RowNo Int) 
Insert Into @myTable 
Select capture_instance, ROW_NUMBER() Over(Order By Source_Object_Id) As RN From cdc.change_tables 

Set @RowCount = @@ROWCOUNT 

While @RowNo <= @RowCount 
Begin 

Select @Capture_Instance = Capture_instance From @myTable Where RowNo = @RowNo 

Set @strSQL = 'sys.sp_cdc_disable_table @source_schema = N''' + Left(@Capture_Instance, CharIndex('_', @Capture_Instance) - 1)  + ''', 
    @source_name = N''' + SubString(@Capture_Instance, CharIndex('_', @Capture_Instance) + 1, Len(@Capture_Instance)) + ''',
    @capture_instance = N''All'''

Exec sp_ExecuteSQL @strSQL /*Diabling the sp_cdc*/

Set @strSQL = 'sys.sp_cdc_enable_table @source_schema = N''' + Left(@Capture_Instance, CharIndex('_', @Capture_Instance) - 1)  + '''
    ,@source_name = N''' + SubString(@Capture_Instance, CharIndex('_', @Capture_Instance) + 1, Len(@Capture_Instance)) + '''
    ,@role_name = N''' + 'cdc_Admin' + '''
    ,@fileGroup_Name = N''' + 'CDCFileGroup' + ''';'

Exec sp_ExecuteSQL @strSQL /*Enabling the sp_cdc, with a new CDCFileGroup(this filegroup would have been created before running this script)*/

Set @RowNo += 1 
End