Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_cdc_cleanup_job_entries

  No additional text.


Syntax
create procedure sys.sp_cdc_cleanup_job_entries
(
	@event_type sysname,
	@old_database_name sysname,
	@new_database_name sysname
)
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @database_id INT
		,@job_id uniqueidentifier
		,@step_id INT
		,@job_type nvarchar(20)

	declare #hjob cursor local fast_forward
	for
		select c.job_id, s.step_id, c.job_type, c.database_id
			from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobsteps s on c.job_id = s.job_id
			where s.database_name = @old_database_name collate database_default

	open #hjob
	fetch #hjob into @job_id, @step_id, @job_type, @database_id

	while (@@fetch_status <> -1)
	begin
		if (@event_type = N'DROP_DATABASE')
		begin
			exec msdb.dbo.sp_delete_job @job_id = @job_id
		end
		else if (@event_type = N'ALTER_DATABASE')
		begin	
			exec msdb.dbo.sp_update_jobstep @job_id = @job_id, @step_id = @step_id, @database_name = @new_database_name
		end
		fetch #hjob into @job_id, @step_id, @job_type, @database_id
	end	
	close #hjob
	deallocate #hjob


	if (@event_type = N'DROP_DATABASE')
	begin
		-- remove the record from cdc_jobs
		delete from msdb.dbo.cdc_jobs
		    where (database_id = @database_id or db_name(database_id) is null)

		-- if this is the last job, drop the table
		if not exists (select database_id from msdb.dbo.cdc_jobs)
		    drop table msdb.dbo.cdc_jobs
	end
	
	return 0
	
end

 
Last revision 2008RTM
See also

  sp_MScdc_db_ddl_event (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