May 16, 2012

sp_MShelpmergeidentity (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_MShelpmergeidentity(nvarchar @publication)

MetaData:

 create procedure sys.sp_MShelpmergeidentity   
@publication sysname
as
declare @pubid uniqueidentifier
declare @artid uniqueidentifier
declare @nickname int
declare @next_seed bigint
declare @retcode int
declare @tablename sysname
declare @range bigint
declare @threshold int
declare @db_name sysname
declare @tmp_table TABLE (tablename sysname, next_seed bigint, range bigint, threshold int, nickname int)
declare @publishingservername sysname
declare @subid uniqueidentifier

--
-- To public.
--
set nocount on
if (@publication is null)
begin
RAISERROR(14003, 16, -1)
return (1)
end

select @db_name = db_name()
,@publishingservername = publishingservername()

--
-- Security Check.
--
exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @db_name, @publishingservername, @pubid output
if @retcode <> 0 or @@error <> 0
return 1


select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles where pubid=@pubid and identity_support=1 order by nickname ASC
while (@artid is not NULL)
begin
-- we need a local subid to look up the entry in MSmerge_identity_range
select @subid=subid from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)

insert @tmp_table (tablename, next_seed, range, threshold, nickname)
select object_name(a.objid), i.max_used, a.range, a.threshold, a.nickname
from dbo.sysmergearticles a
inner join dbo.MSmerge_identity_range i on i.artid=a.artid and i.subid=@subid and i.is_pub_range=1
where a.artid = @artid and a.pubid = @pubid
if @@ERROR<>0
begin
raiserror(21197, 16, -1)
return (1)
end
select @artid = NULL
select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles
where pubid=@pubid and nickname>@nickname and identity_support=1 order by nickname ASC
end
select t.* from @tmp_table t, dbo.sysmergearticles sma
where t.nickname = sma.nickname
and sma.pubid = @pubid
order by sma.processing_order ASC, sma.nickname ASC

return (0)

No comments:

Post a Comment

Total Pageviews