create procedure sys.sp_MSscript_insert_subwins
(
@publication sysname -- publication name
,@article sysname -- article name
,@objid int -- object id
,@artid int -- article id
,@identity_insert bit -- enable identity insert
)
as
begin
declare @cmd nvarchar(4000)
,@qualname nvarchar(517)
,@rc int
,@fhasnonpkuniquekeys int
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'
if (@execution_mode = @QSubWins)
begin
'+N'
'+N'-- Subscriber wins resolution
'+N'-- '
insert into #proctext(procedure_text) values( @cmd )
-- script this block if the article has non PK unique keys
if (@fhasnonpkuniquekeys = 1)
begin
select @cmd = N'
if (@cftcase = 22)
begin
'+N'
'+N'-- delete rows with values of non PK keys
'+N'-- '
insert into #proctext(procedure_text) values( @cmd )
-- script delete rows with values for non PK keys
select @cmd = N'
delete ' + @qualname
insert into #proctext(procedure_text) values( @cmd )
exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
,@artid = @artid
,@prefix = N'@c'
,@suffix = NULL
,@mode = 7
-- continue scripting
select @cmd = N'
end'
insert into #proctext(procedure_text) values( @cmd )
end
-- continue scripting
select @cmd = N'
if (@cftcase = 21)
begin
'+N'
'+N'-- delete rows with values of all keys
'+N'-- '
insert into #proctext(procedure_text) values( @cmd )
-- script delete rows with values of all keys
select @cmd = N'
delete ' + @qualname
insert into #proctext(procedure_text) values( @cmd )
exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
,@artid = @artid
,@prefix = N'@c'
,@suffix = NULL
,@mode = 6
-- continue scripting
select @cmd = N'
end
if (@cftcase in (21,22))
begin
'+N'
'+N'-- insert row
'+N'-- '
insert into #proctext(procedure_text) values( @cmd )
-- script insert row
exec @rc = sp_script_insertforcftresolution
@objid = @objid
,@artid = @artid
,@identity_insert = @identity_insert
,@prefix = N'@c'
,@suffix = NULL
-- continue scripting
select @cmd = N'
end
'+N'
'+N'--
'+N'-- all done for conflict resolution for Subscriber Wins policy
'+N'--
'+N'
end'
insert into #proctext(procedure_text) values( @cmd )
-- all done
return 0
end