Groups | Blog | Home
all groups > sql server replication > may 2006 >

sql server replication : Show pending merge changes



babu.mani NO[at]SPAM gmail.com
5/24/2006 8:32:55 PM
I have changed Paul Ibison's stored proc a little bit. This proc
should wok for both Central and Branch database and lists for all
replicated articles, so parameter is optional. Also it eliminates
duplication.

Let me know if there is any flaw.

CREATE PROC PBS_sp_ShowPendingMergeChanges (@p_articlename sysname =
'%')

AS

BEGIN

-- Fetch the rowguidcol of the article
declare @ROWGUIDCol sysname
declare @sql varchar(8000)
declare @articlename sysname

create table #t
(
Publisher varchar(50),
Publication varchar(50),
Article varchar(50),
Type varchar(15),
PrimaryKey uniqueidentifier
)

-- Declare cursor to report for all articles
DECLARE PBS_cs_mergearticles CURSOR LOCAL FAST_FORWARD FOR
SELECT ltrim(rtrim(name)) FROM sysmergearticles where name like
@p_articlename

OPEN PBS_cs_mergearticles

FETCH NEXT FROM PBS_cs_mergearticles INTO @articlename

WHILE @@FETCH_STATUS = 0 BEGIN

select @ROWGUIDCol = c.[name]
from syscolumns c
where c.id = object_id(@articlename)
and columnproperty(object_id(@articlename), c.[name],
'IsRowGUIDCol') = 1

if @ROWGUIDCol is null
return -- Can't determine the rowguidcol so return null

set @sql =
'SELECT distinct ' +
' sysmergepublications.publisher AS Publisher, ' +
' sysmergepublications.name AS Publication, ' +
' sysmergearticles.name AS Article, ' +
' ''Ins/Upd'' as Type, ' +
' MSmerge_contents.rowguid AS PrimaryKey ' +
-- '[' + @articlename + '].* ' +
'FROM ' +
' MSmerge_contents with (nolock) ' +
' INNER JOIN [' + @articlename + '] with (nolock) ' +
' ON MSmerge_contents.rowguid = [' + @articlename + '].' +
@ROWGUIDCol +
' INNER JOIN sysmergearticles with (nolock) ' +
' ON MSmerge_contents.tablenick = sysmergearticles.nickname ' +
' INNER JOIN sysmergesubscriptions with (nolock) ' +
' ON sysmergearticles.pubid = sysmergesubscriptions.partnerid ' +
' AND sysmergesubscriptions.db_name = db_name() ' +
' INNER JOIN sysmergepublications with (nolock) ' +
' ON sysmergesubscriptions.pubid = sysmergepublications.pubid ' +
' WHERE ' +
' sysmergearticles.name = ''' + @articlename + ''' ' +
' AND sysmergearticles.gen_cur = MSmerge_contents.generation ' +

' UNION ALL ' +

' SELECT distinct ' +
' sysmergepublications.publisher, ' +
' sysmergepublications.name, ' +
' sysmergearticles.name, ' +
' ''Del'', ' +
' MSmerge_tombstone.rowguid ' +
-- '[' + @articlename + '].* ' +
' FROM ' +
' MSmerge_tombstone with (nolock) ' +
' INNER JOIN sysmergearticles with (nolock) ' +
' ON MSmerge_tombstone.tablenick = sysmergearticles.nickname ' +
' INNER JOIN sysmergesubscriptions with (nolock) ' +
' ON sysmergearticles.pubid = sysmergesubscriptions.partnerid ' +
' AND sysmergesubscriptions.db_name = db_name() ' +
' INNER JOIN sysmergepublications with (nolock) ' +
' ON sysmergesubscriptions.pubid = sysmergepublications.pubid ' +
' LEFT OUTER JOIN [' + @articlename + ']' +
' ON MSmerge_tombstone.rowguid = [' + @articlename + '].' +
@ROWGUIDCol +
' WHERE sysmergearticles.name = ''' + @articlename + '''' +
' AND sysmergearticles.gen_cur = MSmerge_tombstone.generation '

INSERT INTO #t
Exec (@sql)


FETCH NEXT FROM PBS_cs_mergearticles INTO @articlename

END

CLOSE PBS_cs_mergearticles
DEALLOCATE PBS_cs_mergearticles

Select * from #t order by publisher, publication, article, type,
primarykey

END

GO
Paul Ibison
5/25/2006 11:33:34 AM
Thanks - I'll check it out. The one I use locally also has distinct and I
never actually got round to updating the script on the web.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com

Paul Ibison
5/30/2006 8:19:15 PM
Actually there's a couple of additions to the script that have been pointed
out and you might want to take a look:
http://www.replicationanswers.com/Script9.asp
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com


Patrick Molijn
6/3/2006 2:08:59 AM
If you're running SQL 2005 this will not work.
Check out http://www.replicationanswers.com/Script9.asp for a SQL2005 and
SQL 2000 version of the SP.
But wait, there's more.
Starting with SQL2005 we got a nice stored procedure from the folks from
Redmond themselves.
sp_showpendingchanges

Please check out this Stored Procedure in BOL. It might just be the SP you
were looking for.

Cheers,
Patrick Molijn

[quoted text, click to view]

Raju
4/10/2008 12:14:43 AM
This stored procedure does not work, if the merge agent has started and failed to synchronize (may be due to a network issue).

From http://www.developmentnow.com/g/114_2006_5_0_0_762643/Show-pending-merge-changes.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button