Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_cdc_disable_table_instance

  No additional text.


Syntax
create procedure [sys].[sp_cdc_disable_table_instance]
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname
)
as
begin
    set nocount on
	
	declare @change_table sysname
		,@retcode int
		,@object_id int
		,@stmt nvarchar(max)
		,@action nvarchar(1000)
		,@table_resource nvarchar(255)
		,@applock_result int
		,@source_object_id int
		,@raised_error int
		,@raised_message nvarchar(4000)
        ,@instance_resource nvarchar(255)

	set @raised_error = 0		
	set @capture_instance = rtrim(@capture_instance)
	set @source_schema    = rtrim(@source_schema)	
	set @source_name      = rtrim(@source_name)	
	set @object_id = object_id('[cdc].' + quotename(@capture_instance + N'_CT'))
	set @source_object_id = object_id(quotename(@source_schema) + N'.' + quotename(@source_name))
    select @table_resource = N'__$cdc__table_' + convert(nvarchar(10),@source_object_id)
	
	--  Get exclusive table lock
	exec @applock_result = sys.sp_getapplock @Resource = @table_resource, @LockMode = N'Exclusive',
		@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
	If @applock_result < 0
	begin
		-- Lock request failed.
		set @action = N'sys.sp_getapplock @Resource = ' + @table_resource + N'@LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' '
		raiserror(22840, 16, -1, @action, @applock_result)
	end
	
	--  Get exclusive instance lock
	set @instance_resource = quotename(@capture_instance)
	set @action = N'sys.sp_getapplock @Resource = @instance_resource, @LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' '
	exec @applock_result = sys.sp_getapplock @Resource = @instance_resource, @LockMode = N'Exclusive',
		@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
	If @applock_result < 0
	begin
		-- Lock request failed.
		raiserror(22840, 16, -1, @action, @applock_result)
	end
		
	BEGIN TRY
	
		-- Drop entries for the capture instance in [cdc].[index_columns].
		set @action = N'delete from [cdc].[index_columns] where object_id = @object_id'
		delete from [cdc].[index_columns]
		where object_id = @object_id
		
		-- Drop entries for the capture instance in [cdc].[captured_columns].
		set @action = N'delete from [cdc].[captured_columns] where object_id = @object_id'
		delete from [cdc].[captured_columns]
		where object_id = @object_id

		-- Drop entries for the capture instance in [cdc].[ddl_history].
		set @action = N'delete from [cdc].[ddl_history] where object_id = @object_id'
		delete from [cdc].[ddl_history]
		where object_id = @object_id
	
		-- Drop cdc objects associated with the change table.
		set @action = N'sp_cdc_drop_change_table_objects ' + @capture_instance
		exec @retcode = [sys].[sp_cdc_drop_change_table_objects] @capture_instance

		-- Remove entry for change table in [cdc].[change_tables].
		set @action = N'delete from [cdc].[change_tables] where object_id = @object_id'
		delete [cdc].[change_tables]
		where object_id = @object_id
		
	END TRY	
	
	BEGIN CATCH
	
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH

	if (@raised_error <> 0)
	begin
		raiserror(22837, 16, -1, @capture_instance, @action, @raised_error, @raised_message)
		return 1
	end	
		
	return 0	
end

 
Last revision 2008RTM
See also

  sp_cdc_disable_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