April 27, 2012

sp_helpmergealternatepublisher (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_helpmergealternatepublisher(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication)

MetaData:

 create procedure sys.sp_helpmergealternatepublisher (  
@publisher sysname, -- Publisher server --
@publisher_db sysname, -- Publisher database --
@publication sysname -- Publication name --
) AS

SET NOCOUNT ON
declare @subid uniqueidentifier
declare @pubid uniqueidentifier
declare @distributor sysname
declare @retcode int

declare @MShelpmergealternatepublisher TABLE
(
subid uniqueidentifier not null,
alternate_publisher sysname collate database_default not null,
alternate_publisher_db sysname collate database_default not null,
alternate_publication sysname collate database_default not null,
alternate_distributor sysname collate database_default null,
friendly_name nvarchar(255) collate database_default null,
enabled bit not null
)

set @publisher= LOWER(@publisher collate SQL_Latin1_General_CP1_CS_AS)

--
-- Select the subscription's pubid and subid
--
select @pubid = pubid from dbo.sysmergepublications
where name = @publication and
LOWER(publisher collate SQL_Latin1_General_CP1_CS_AS) = @publisher and
publisher_db = @publisher_db
if @pubid is NULL
begin
-- since we are adding a sysmergepublications entry for the alternate publisher
-- see sp_MScreateglobalreplica - the entry should be there
raiserror (21423, 11, -1, @publication)
return (1)
end

if 1 <> {fn ISPALUSER(@pubid)}
begin
raiserror(21423, 11, -1, @publication)
return (1)
end

insert into @MShelpmergealternatepublisher
(subid, alternate_publisher, alternate_publisher_db,
alternate_publication, alternate_distributor, friendly_name, enabled)
select distinct pub.pubid, pub.publisher, pub.publisher_db,
pub.name, pub.distributor, alt.description, 1
from dbo.sysmergepublications pub, dbo.MSmerge_altsyncpartners alt
where pub.pubid = alt.alternate_subid and alt.subid = @pubid

insert into @MShelpmergealternatepublisher
(subid, alternate_publisher, alternate_publisher_db,
alternate_publication, alternate_distributor, friendly_name, enabled)
select pubid, publisher, publisher_db,
name, distributor, description, 1
from dbo.sysmergepublications where pubid = @pubid

insert into @MShelpmergealternatepublisher
(subid, alternate_publisher, alternate_publisher_db,
alternate_publication, alternate_distributor, friendly_name, enabled)
select distinct pub.pubid, pub.publisher, pub.publisher_db,
pub.name, pub.distributor, sub.description, 0
from dbo.sysmergepublications pub, dbo.sysmergesubscriptions sub
where pub.pubid not in (select subid from dbo.MSmerge_altsyncpartners) and
pub.pubid not in (select alternate_subid from dbo.MSmerge_altsyncpartners) and
pub.pubid not in (select subid from @MShelpmergealternatepublisher) and
sub.pubid = pub.pubid and sub.pubid = sub.subid

select distinct alternate_publisher,
alternate_publisher_db,
alternate_publication,
alternate_distributor,
friendly_name,
enabled
from @MShelpmergealternatepublisher
order by alternate_publisher, alternate_publisher_db, alternate_publication, alternate_distributor

return (0)

No comments:

Post a Comment

Total Pageviews