sp_helptracertokens (Transact-SQL)

适用于:SQL ServerAzure SQL 托管实例

为每个插入到发布以确定滞后时间的跟踪标记分别返回一行。 此存储过程在发布服务器上的发布数据库中执行,或者在分发服务器上的分发数据库中执行。

Transact-SQL 语法约定

语法

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

参数

[ @publication = ] 'publication' 在其中插入跟踪令牌的发布的名称。 publicationsysname,没有默认值。

[ @publisher = ] 'publisher' 发布服务器的名称。 publishersysname,默认值为 NULL。

注意

应仅为非 Microsoft SQL Server 发布服务器指定此参数。

[ @publisher_db = ] 'publisher_db' 发布数据库的名称。 publisher_dbsysname,默认值为 NULL。 如果在发布服务器上执行该存储过程,将忽略此参数。

结果集

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

返回代码值

0 (成功) 或 1 (失败)

备注

sp_helptracertokens 用于事务复制。

sp_helptracertokens 用于在执行 sp_helptracertokenhistory (Transact-SQL) 时获取跟踪令牌 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

另请参阅

为事务复制测量滞后时间和验证连接
sp_deletetracertokenhistory (Transact-SQL)