Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_ddl_triggers

  No additional text.


Syntax
create procedure sys.sp_MSrepl_ddl_triggers
(
	@type varchar(5)	-- valid input is 'merge' or 'tran'
	,@mode varchar(4) -- valid input is 'add' or 'drop'
)
AS
begin
    declare @retcode int
    			,@type_id int  -- 1 is for tran, 2 is for merge
    			,@mode_id int -- 1 is add, 2 is drop
    			


    -- deligate to sp_MSmerge(tran)_* counterparts
    declare @events table (event_name nvarchar(4000), proc_name sysname, procmapid int)
    insert into @events values (N'ALTER_TABLE', N'altertable', 1)
    insert into @events values (N'ALTER_VIEW', N'alterview', 2)
    insert into @events values (N'ALTER_FUNCTION, ALTER_PROCEDURE', N'alterschemaonly', 3)
    insert into @events values (N'ALTER_TRIGGER', N'altertrigger', 4)

    declare @alter_table_trigger sysname
				,@event_name nvarchar(4000)
				,@proc_name sysname
				,@cmd nvarchar(4000)
				,@procmapid int

	
	-- check input, first @type, then @mode
	
	IF lower(@type) = 'tran'
	BEGIN
		set @type_id = 1
	END
	ELSE IF lower(@type) = 'merge'
	BEGIN
		set @type_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@type)
	    RETURN(1)
	END

	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
	
	
	--cursor through list of events we support
	
	declare #event_cur cursor LOCAL FAST_FORWARD for
		select event_name, proc_name, procmapid from @events
	open #event_cur
	fetch #event_cur into @event_name, @proc_name, @procmapid
	while (@@fetch_status = 0)
	begin
		
		--build trigger name
		
		select @alter_table_trigger = case @type_id
															when 1 then N'tr_MStran_'
															when 2 then N'MSmerge_tr_'
														end
													+ @proc_name
		
		
		--drop trigger
		
		if (@mode_id = 2) and exists (select * from sys.triggers where name = @alter_table_trigger)
		begin
			select @cmd =  N'drop trigger ' + @alter_table_trigger + '  on database'
			exec (@cmd)
		end
		
		--create trigger
		
		else	if (@mode_id = 1) and not exists (select * from sys.triggers where name = @alter_table_trigger)
		begin
			-- no dbo. here since
			-- you cannot specify schema name as a prefix to the trigger name for database and server level triggers.
			select @cmd = N'create trigger ' + @alter_table_trigger +
			            ' on database for ' + @event_name +
			            ' 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 ' + case @type_id when 1 then N'sys.sp_MStran_ddlrepl '
			            											when 2 then N'sys.sp_MSmerge_ddldispatcher '
			            				end
			            	+ N'@EventData, ' + cast(@procmapid as nvarchar(10))
			exec (@cmd)
			if @@ERROR<>0
			begin
				if (@type_id = 2)	
					raiserror(21532, 16, -1, @event_name)
				else if (@type_id = 1)
					raiserror(21722, 16, -1, @event_name)
				return (1)
			end
			-- mark as ms shipped, no need to escape on @alter_table_trigger, we build this tring here
		    execute sp_MS_marksystemobject @alter_table_trigger , 'database'
		    if @@ERROR<>0
			begin
				raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
				return (1)
			end
        end
        fetch #event_cur into @event_name, @proc_name, @procmapid
    end
    return 0
end

 
Last revision 2008RTM
See also

  sp_addmergesubscription (Procedure)
sp_dropmergepullsubscription (Procedure)
sp_mergesubscription_cleanup (Procedure)
sp_MSCleanupForPullReinitWithPubId (Procedure)
sp_MScreate_all_article_repl_views (Procedure)
sp_MScreate_pub_tables (Procedure)
sp_MSdrop_pub_tables (Procedure)
sp_MSmergepublishdb (Procedure)
sp_MSmergesubscribedb (Procedure)
sp_MSremovedbreplication (Procedure)
sp_MSupdateinitiallightweightsubscription (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