Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_cdc_create_change_table_index

  No additional text.


Syntax
create procedure sys.sp_cdc_create_change_table_index
(
	@capture_instance sysname,
	@supports_net_changes bit
)	
as
begin
	declare @stmt nvarchar(max)
		,@change_table nvarchar(1000)
		,@pk_column_list nvarchar(max)
		,@column_name sysname
		
	set nocount on
	
    set @change_table = N'[cdc].' + quotename(@capture_instance + N'_CT')
	
   	set @stmt = N'create unique clustered index ' +
	quotename(@capture_instance + N'_CT_clustered_idx') +
	N' on ' + @change_table + N'
	(
		__$start_lsn ASC,
		__$seqval ASC,
		__$operation ASC
	)'	 	
	
	exec (@stmt)
	if (@@error != 0)
	begin
		return 1
	end
	
	if @supports_net_changes = 0
	begin
		return 0
	end
		
    set @pk_column_list = N' '
		
	create table #index_column_names(column_name sysname, index_ordinal int)

	insert into #index_column_names
	select column_name, index_ordinal
	from [cdc].[index_columns] where object_id = object_id(@change_table)

   	declare #hidxcolumns cursor local fast_forward for
		select column_name
		from #index_column_names
		order by index_ordinal
		
	open #hidxcolumns
	fetch #hidxcolumns into @column_name
	
	while (@@fetch_status <> -1)
	begin
		set @pk_column_list = @pk_column_list + quotename(@column_name) +  N' ASC, '

		fetch #hidxcolumns into @column_name
	end
	
	close #hidxcolumns
	deallocate #hidxcolumns
	
	set @stmt = N' create unique nonclustered index ' +
		quotename(@capture_instance + N'_CT_idx') +
		N' on ' + @change_table + N'
		( '  + @pk_column_list + N'
			[__$seqval] ASC,
			[__$operation] ASC
		) INCLUDE ( [__$start_lsn], [__$update_mask] )'	 	
	
	exec (@stmt)
	if (@@error != 0)
	begin
		return 1
	end
	
	return 0
end

 
Last revision 2008RTM
See also

  sp_cdc_enable_table_internal (Procedure)
sp_MSdrop_cdc (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash