Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MScdc_ddl_server_trigger

  No additional text.


Syntax
create procedure sys.sp_MScdc_ddl_server_trigger
(
	@mode varchar(4) -- valid input is 'add' or 'drop'
)
AS
begin
    declare @retcode int
				,@db_name sysname
    			,@mode_id int -- 1 is add, 2 is drop

	IF lower(@mode) = 'add'
	BEGIN
		set @mode_id = 1
	END
	ELSE IF lower(@mode) = 'drop'
	BEGIN
		set @mode_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@mode)
	    RETURN(1)
	END
	
	
	--drop trigger
	
	if (@mode_id = 2)
	begin
		-- if this is the last db with cdc enabled, drop server ddl trigger as well
		if not exists (select * from sys.databases where database_id <> db_id() and is_cdc_enabled = 1)
			and exists (select * from sys.server_triggers where name = N'tr_MScdc_db_ddl_event')
		begin
			exec(N'drop trigger tr_MScdc_db_ddl_event on all server')
		end
	end

	
	--create trigger
	
	else if (@mode_id = 1)
	begin
		--if there is at least one db enabled for CDC, or for whatever reason server ddl trigger didn't exists, create it now
		if not exists (select * from sys.server_triggers where name = N'tr_MScdc_db_ddl_event')
		begin
			-- no dbo. here since
			-- you cannot specify schema name as a prefix to the trigger name for database and server level triggers.
			exec(N'create trigger tr_MScdc_db_ddl_event on all server for ALTER_DATABASE, DROP_DATABASE
		             as
					set ANSI_NULLS ON
					set ANSI_PADDING ON
					set ANSI_WARNINGS ON
					set ARITHABORT ON
					set CONCAT_NULL_YIELDS_NULL ON
					set NUMERIC_ROUNDABORT OFF
					set QUOTED_IDENTIFIER ON

					declare @EventData xml, @retcode int
					set @EventData=EventData()
					if object_id(''sys.sp_MScdc_db_ddl_event'' ) is not null
					begin
						exec @retcode = sys.sp_MScdc_db_ddl_event @EventData
						if @@error <> 0 or @retcode <> 0
						begin
							rollback tran
						end
					end		 ')


			if @@ERROR<>0
			begin
				set @db_name = db_name()
				raiserror(22968, 16, -1, N'tr_MScdc_db_ddl_event', @db_name)
				return (1)
			end
		
			-- mark as ms shipped, no need to escape on @alter_table_trigger, we build this string here
			execute @retcode = sp_MS_marksystemobject N'tr_MScdc_db_ddl_event', 'server'
			if @retcode <> 0
			begin
				raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
				return (1)
			end			
		end
	end
		
    return 0
end

 
Last revision 2008RTM
See also

  sp_cdc_disable_db_internal (Procedure)
sp_cdc_enable_db_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