Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MScdc_ddl_database_triggers

  No additional text.


Syntax
create procedure sys.sp_MScdc_ddl_database_triggers
(
	@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 exists (select * from sys.triggers where name = N'tr_MScdc_ddl_event')
		begin
			exec(N'drop trigger tr_MScdc_ddl_event on database')
		end
	end

	
	--create trigger
	
	else if (@mode_id = 1)
	begin
		if not exists (select * from sys.triggers where name = N'tr_MScdc_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_ddl_event on database for ALTER_TABLE, DROP_TABLE, ALTER_INDEX, DROP_INDEX
		             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
						set @EventData=EventData()
						exec sys.sp_MScdc_ddl_event @EventData')

			if @@ERROR<>0
			begin
				set @db_name = db_name()
				raiserror(22968, 16, -1, N'tr_MScdc_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_ddl_event', 'database'
			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