使用合并复制中的T-SQL从订阅服务器删除推送订阅

时间:2012-04-21 07:03:22

标签: sql-server-2008 tsql replication subscription merge-replication

我有一个使用合并复制同步的Publisher服务器和订阅服务器。当我使用向导删除复制时,登录窗口要求我登录Subscriber Server并删除其订阅,但是当我使用生成的脚本删除复制时,订阅者中的订阅将不会删除。我怎样才能使用TSQL? 换句话说: 我想使用T-SQL

连接到订阅者并删除订阅者的订阅记录

2 个答案:

答案 0 :(得分:1)

要删除合并推送订阅,您必须连接到发布服务器和订阅服务器。每How to: Delete a Push Subscription (Replication Transact-SQL Programming) - 在发布商处执行sp_dropmergesubscription,在订阅者处执行sp_mergesubscription_cleanup

答案 1 :(得分:1)

最后我找到了解决问题的方法:

我使用Linked Server创建了与远程服务器的连接:

exec sp_addlinkedserver 'RemoteServer\PeerInstance', N'SQL Server'

exec sp_addlinkedsrvlogin 'RemoteServer\PeerInstant', 'true', 'sa', 'password'

exec ReplicatedDBOnMainServer.sys.sp_dropmergesubscription
@publication = N'PublicationName', 
@subscriber = N'RemoteServer\PeerInstant'

exec [RemoteServer\PeerInstant].ReplicatedDBOnRemote.sys.sp_mergesubscription_cleanup
@publisher = N'MainServer\MainInstant', 
@publisher_db = N'ReplicatedDBOnMainServer'
@publication = N'PublicationName'