sp_helptracertokens (Transact-SQL)

适用于:SQL ServerAzure SQL 托管实例

为每个插入发布以确定延迟的跟踪令牌返回一行。 此存储过程在发布服务器上的发布数据库中执行,或者在分发服务器上的分发数据库中执行。

Transact-SQL 语法约定

语法

sp_helptracertokens
    [ @publication = ] N'publication'
    [ , [ @publisher = ] N'publisher' ]
    [ , [ @publisher_db = ] N'publisher_db' ]
[ ; ]

参数

[ @publication = ] N'publication'

插入跟踪令牌的发布的名称。 @publicationsysname,无默认值。

[ @publisher = ] N'publisher'

发布服务器的名称。 @publisher为 sysname,默认值为 NULL.

只能为非 SQL Server 发布服务器指定@publisher

[ @publisher_db = ] N'publisher_db'

发布数据库的名称。 @publisher_db为 sysname,默认值为 NULL. 如果在发布服务器上执行存储过程,则忽略@publisher_db

结果集

列名称 数据类型 说明
tracer_id int 标识跟踪令牌记录。
publisher_commit datetime 在发布服务器的发布数据库中提交标记记录的日期和时间。

返回代码值

0(成功)或 1(失败)。

注解

sp_helptracertokens用于事务副本 (replica)。

sp_helptracertokens 用于在执行 sp_helptracertokenhistory时获取跟踪令牌 ID。

示例

DECLARE @publication AS sysname;
DECLARE @tokenID AS int;
SET @publication = N'AdvWorksProductTran'; 

USE [AdventureWorks2022]

-- Insert a new tracer token in the publication database.
EXEC sys.sp_posttracertoken 
  @publication = @publication,
  @tracer_token_id = @tokenID OUTPUT;
SELECT 'The ID of the new tracer token is ''' + 
    CONVERT(varchar,@tokenID) + '''.'
GO

-- Wait 10 seconds for the token to make it to the Subscriber.
WAITFOR DELAY '00:00:10';
GO

-- Get latency information for the last inserted token.
DECLARE @publication AS sysname;
DECLARE @tokenID AS int;
SET @publication = N'AdvWorksProductTran'; 

CREATE TABLE #tokens (tracer_id int, publisher_commit datetime)

-- Return tracer token information to a temp table.
INSERT #tokens (tracer_id, publisher_commit)
EXEC sys.sp_helptracertokens @publication = @publication;
SET @tokenID = (SELECT TOP 1 tracer_id FROM #tokens
ORDER BY publisher_commit DESC)
DROP TABLE #tokens

-- Get history for the tracer token.
EXEC sys.sp_helptracertokenhistory 
  @publication = @publication, 
  @tracer_id = @tokenID;
GO

权限

只有 sysadmin 固定服务器角色的成员发布数据库中的db_owner固定数据库角色,或db_owner分发数据库中的固定数据库或 replmonitor 角色才能执行sp_helptracertokenhistory