有没有人知道查询sql server(2008)的最后同步日期。
复制监视器中显示的信息相同,但我希望能够从查询中获取该日期。
答案 0 :(得分:3)
我创建了一个这样的视图来获取订阅者的最后日期
select subscriber_name, max(start_time) as last_sync
from msMerge_sessions inner join msMerge_agents
on msmerge_agents.id = msmerge_sessions.agent_id
group by subscriber_name
我调用了视图'LastSync' - 然后我加入了这样的视图,以获得类似于复制监视器显示的表示。
SELECT dbo.LastSync.id, dbo.LastSync.subscriber_name, dbo.LastSync.creation_date, dbo.LastSync.last_sync,
distribution.dbo.MSmerge_sessions.estimated_upload_changes + distribution.dbo.MSmerge_sessions.estimated_download_changes AS estimate_rows,
distribution.dbo.MSmerge_sessions.upload_inserts + distribution.dbo.MSmerge_sessions.upload_updates + distribution.dbo.MSmerge_sessions.upload_deletes + distribution.dbo.MSmerge_sessions.download_inserts
+ distribution.dbo.MSmerge_sessions.download_updates + distribution.dbo.MSmerge_sessions.download_deletes AS actual_rows,
distribution.dbo.MSmerge_sessions.duration AS total_seconds, distribution.dbo.MSmerge_sessions.percent_complete,
distribution.dbo.MSmerge_sessions.delivery_rate, CASE (runstatus)
WHEN 1 THEN 'Start' WHEN 2 THEN 'Succeed' WHEN 3 THEN 'In Progress' WHEN 4 THEN 'Idle' WHEN 5 THEN 'Retry' WHEN 6 THEN 'Fail' END AS Status
FROM distribution.dbo.MSmerge_sessions INNER JOIN
dbo.LastSync ON dbo.LastSync.id = distribution.dbo.MSmerge_sessions.agent_id AND distribution.dbo.MSmerge_sessions.start_time = dbo.LastSync.last_sync
答案 1 :(得分:2)
您可以使用系统表msMerge_sessions查看有关合并会话的大量信息:
select * from msMerge_sessions
根据您需要的信息,使用数据库中提供的其他系统表。
答案 2 :(得分:0)
对于已回答的号码3
非常努力但是在运行查询
的能力视图上进行了一些修改----创建View LastSync,如下所示
Create View LastSync As
select subscriber_name, max(start_time) as last_sync, ID, creation_date
from msMerge_sessions inner join msMerge_agents
on msmerge_agents.id = msmerge_sessions.agent_id
group by subscriber_name, ID, creation_date
Go
----运行以下查询
SELECT dbo.LastSync.id,dbo.LastSync.subscriber_name, dbo.LastSync.creation_date,dbo.LastSync.last_sync, distribution.dbo.MSmerge_sessions.estimated_upload_changes + distribution.dbo.MSmerge_sessions.estimated_download_changes AS estimate_rows,distribution.dbo.MSmerge_sessions.upload_inserts + distribution.dbo.MSmerge_sessions.upload_updates + distribution.dbo.MSmerge_sessions.upload_deletes + distribution.dbo.MSmerge_sessions.download_inserts + distribution.dbo.MSmerge_sessions.download_updates + distribution.dbo.MSmerge_sessions.download_deletes AS actual_rows, distribution.dbo.MSmerge_sessions.duration AS total_seconds, distribution.dbo.MSmerge_sessions.percent_complete, distribution.dbo.MSmerge_sessions.delivery_rate,CASE(runstatus) 什么时候开始'当2那时成功' 3那时正在进行中' 当4那么空闲' 5,那么'重试'当6那么失败'结束为 状态FROM distribution.dbo.MSmerge_sessions INNER JOIN dbo.LastSync ON dbo.LastSync.id = distribution.dbo.MSmerge_sessions.agent_id AND distribution.dbo.MSmerge_sessions.start_time = dbo.LastSync.last_sync
- 祝你好运