May 21, 2012

sp_MShelptracertokens (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_MShelptracertokens(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication)

MetaData:

   
--
-- Name:
-- sp_MShelptracertokens
--
-- Description:
-- This procedure is used to retrieve the tracer token lsns.
-- It returns a list of the time a publisher_commit a tracer token along with the
-- tracer token lsn which can be used when calling sp_MShelptracertokenhistory.
--
-- Parameters:
-- @publisher sysname
-- @publisher_db sysname
-- @publication sysname
--
-- Returns:
-- 0 - succeeded
-- 1 - failed
--
-- Result:
-- (see description)
--
-- Security:
-- DBO or replmonitor of distribution db (used by the UI)
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelptracertokens
(
@publisher sysname,
@publisher_db sysname,
@publication sysname
)
as
begin
set nocount on

declare @retcode int,
@publication_id int,
@distribution_db sysname

select @distribution_db = db_name()

--
-- security check.
-- User must be member of 'replmonitor' role in distribution database
--
exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess @distribution_db = @distribution_db
if @retcode != 0 or @@error != 0
return 1

-- Has to be executed from distribution database
if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
begin
-- sp_MSispeertopeeragent can only be executed in the distribution database.
raiserror (21482, 16, -1, 'sp_MShelptracertokens', 'distribution')
return 1
end

-- check to see if the publication exists
select @publication_id = msp.publication_id
from dbo.MSpublications msp
join sys.servers ss
on msp.publisher_id = ss.server_id
where UPPER(ss.name) = UPPER(@publisher)
and msp.publisher_db = @publisher_db
and msp.publication = @publication

if @publication_id is NULL
begin
-- Publication 'publication' does not exist.
raiserror(21200, 16, -1, @publication)
return 1
end

-- make sure to only return the tracer_ids
-- that have tracer history information.
select tracer_id,
publisher_commit
from MStracer_tokens
where publication_id = @publication_id
and tracer_id in (select parent_tracer_id
from MStracer_history)
order by publisher_commit desc

return 0
end

No comments:

Post a Comment

Total Pageviews