May 10, 2012

sp_MSdist_adjust_identity (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


sys.sp_MSdist_adjust_identity(int @agent_id
, nvarchar @tablename)


 CREATE PROCEDURE sys.sp_MSdist_adjust_identity  
@agent_id int,
@tablename sysname
declare @publisher sysname
declare @publisher_db sysname
declare @publisher_id smallint
declare @publication sysname
declare @next_seed bigint
declare @range bigint
declare @threshold int
declare @retcode int

-- Security check.
exec @retcode = sys.sp_MScheck_pull_access
@agent_id = @agent_id,
@agent_type = 0 -- distribution agent
if @@error <> 0 or @retcode <> 0
return (1)

select @publication = publication, @publisher_id = publisher_id,
@publisher_db = publisher_db from MSdistribution_agents where
id = @agent_id

select @publisher = srvname from master.dbo.sysservers where
srvid = @publisher_id
-- Get the publication id.
-- Note: auto identity range is only supported for queued tran pub
-- which implies independent agent.
declare @publication_id int
select @publication_id = publication_id from dbo.MSpublications where
publication = @publication and
publisher_id = @publisher_id and
publisher_db = @publisher_db

-- Get the source object name
declare @src_object sysname
select @src_object = source_object from MSarticles where
publication_id = @publication_id and
destination_object = @tablename

if @src_object is not null
exec @retcode = sys.sp_MSfetchAdjustidentityrange
@publisher = @publisher,
@publisher_db = @publisher_db,
@tablename = @src_object,
@adjust_only = 1,
@for_publisher = 0,
@next_seed = @next_seed output,
@range = @range output,
@threshold = @threshold output
if @@error <> 0 or @retcode <> 0
return 1

-- Return nothing if the table is not found in the table collection served by
-- the distribution agent.
select 'next_seed' = @next_seed, 'range' = @range, 'threshold' = @threshold
where @next_seed is not null

No comments:

Post a Comment

Total Pageviews