create procedure sys.sp_MScheck_republisher_ranges
@qualified_name nvarchar(300),
@artid uniqueidentifier,
@pub_identity_range bigint = NULL,
@identity_range bigint = NULL
as
declare @objid int
declare @ident_incr numeric(38,0)
declare @root_pubid uniqueidentifier
declare @subid uniqueidentifier
declare @repub_range_begin numeric(38,0)
declare @repub_range_end numeric(38,0)
declare @repub_next_range_begin numeric(38,0)
declare @repub_next_range_end numeric(38,0)
declare @root_pub_range bigint
declare @root_range bigint
declare @root_publisher sysname
-- now get the idrange information for the publication to which this db is a subscriber and
-- has a republisher range allocated.
select @root_pubid=pubid, @root_pub_range = pub_range, @root_range = range from dbo.sysmergearticles where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=0
if @root_pubid is NULL
begin
RAISERROR (20634, 16, -1)
RETURN (1)
end
select @root_publisher = publisher from dbo.sysmergepublications where pubid = @root_pubid
-- for the following comparisons we will convert the ranges to positive numbers if
-- the ident_increment is negative
select @ident_incr = IDENT_INCR(@qualified_name)
if @ident_incr is NULL
begin
RAISERROR(21756, 16, -1, @qualified_name)
return 1
end
if @ident_incr < 0
begin
select @pub_identity_range = -1*@pub_identity_range
select @root_pub_range = -1*@root_pub_range
select @identity_range = -1*@identity_range
select @root_range = -1*@root_range
end
-- now first ensure that the new publisher range is not greater than original pub range
if @pub_identity_range > @root_pub_range/2
begin
raiserror(20660, 16, -1)
return 1
end
if @identity_range > @root_pub_range/2
begin
raiserror(20661, 16, -1)
return 1
end
select @subid=subid from dbo.sysmergesubscriptions
where pubid = @root_pubid and UPPER(subscriber_server)=UPPER(publishingservername()) and db_name=db_name()
if @subid is NULL
begin
raiserror(20021, 16, -1)
return 1
end
-- find the repulisher range which should have been allocated to the global subscription that we are republishing
select @repub_range_begin=range_begin, @repub_range_end=range_end,
@repub_next_range_begin=next_range_begin, @repub_next_range_end=next_range_end
from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=1
if @repub_range_begin is NULL
begin
raiserror(20662, 16, -1, @root_publisher)
return 1
end