Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSscriptdelconflictfinder

  No additional text.


Syntax
create procedure sys.sp_MSscriptdelconflictfinder
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare
			@rc int
			,@cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	
	-- initialize the vars we will use
	
	select @pubid = pubid
	from syspublications
	where name = @publication
	select @artid = artid
	from sysarticles
	where name = @article
		and pubid = @pubid
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	
	--  check if this article has non PK unique keys
	
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	
	-- start scripting
	
	select @cmd = N'
	'+N'
	'+N'-- 
	'+N'-- This is the crux of the proc for conflict resolution
	'+N'-- This code block is essentially a state machine
	'+N'-- where we ascertain the state of resolution
	'+N'-- The actions of this resolution varies for the policy
	'+N'-- The comments for each state outline the policy
	'+N'-- specific actions
	'+N'-- 
	'+N'
	'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- continue scripting
	
	select @cmd = N'
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin
		'+N'
		'+N'-- initialize the conflict case
		'+N'
		select @cftcase = 0

		if (@rowcount = 0)
		begin
			'+N'
			'+N'-- row was deleted or updated
			'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- script row exists with OLD_PK
	
	select @cmd = N'
			if exists (select * from ' + @qualname
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	insert into #proctext(procedure_text) values( N'			)')
	
	-- continue scripting
	
	select @cmd = N'
			begin
				'+N'
				'+N'-- Case 31: Conflict as row was updated
				'+N'-- PubWins 
				'+N'-- generate delete + insert compensating action with values for all unique keys
				'+N'-- SubWins 
				'+N'-- delete row with PK
				'+N'
				select @cftcase = 31
			end'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- continue scripting
	
	select @cmd = N'
			else
			begin
				'+N'
				'+N'-- Case 33: Conflict as row does not exist
				'+N'-- PubWins 
				'+N'-- do nothing
				'+N'-- SubWins 
				'+N'-- do nothing
				'+N'
				select @cftcase = 33
			end
		end'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- continue scripting
	
	select @cmd = N'
		else if (@execution_mode = @QPubWins)
		begin
			'+N'
			'+N'-- we had no conflict for this command
			'+N'-- We need to process this block only in the Publisher Wins cases
			'+N'

			'+N'
			'+N'-- case 30: No conflict - we have to undo the delete
			'+N'-- PubWins 
			'+N'-- generate delete + insert compensating action with values for all unique keys
			'+N'
			select @cftcase = 30
		end	
	end'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- continue scripting
	
	select @cmd = N'

	'+N'
	'+N'-- 
	'+N'-- Now the generation phase
	'+N'-- Use the conflict case value to decide what to do
	'+N'-- 
	'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	
	-- all done
	
	return 0
end

 
Last revision 2008RTM
See also

  sp_MSdrop_repltran (Procedure)
sp_MSscript_sync_del_proc (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