SQL Server:订阅:如何知道表是否在复制/订阅下
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4744282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server : subscription : how to know if a table is under replication/subscription
提问by Posto
In SQL Server, on the "Subscription side", how can you know if a table is under replication/subscription?
在 SQL Server 中,在“订阅端”,如何知道表是否处于复制/订阅状态?
Any idea?
任何的想法?
采纳答案by Damien_The_Unbeliever
I'm not sure there's a simple answer to this, and I think the answers may vary based on the type of replication. I think you may have to rely on heuristics to answer it.
我不确定对此有一个简单的答案,我认为答案可能因复制类型而异。我认为您可能不得不依靠启发式方法来回答它。
For snapshot replication, I'm unable to think of anything that would give the game away. Obviously, the presence of the replication tables (e.g. MSreplication_objects) tells you that replication is occurring within the database, but there aren't any specific clues about tables, so far as I'm aware.
对于快照复制,我想不出任何会泄露游戏的东西。显然,复制表(例如MSreplication_objects)的存在告诉您复制正在数据库内发生,但据我所知,没有关于表的任何特定线索。
For transactional replication (non updating), you may be able to go via MSreplication_objects(which will list some stored procs) and then use sys.sql_dependenciesto locate the tables that these relate to
对于事务复制(非更新),您可以通过MSreplication_objects(将列出一些存储的过程)然后用于sys.sql_dependencies定位与这些相关的表
For transaction replication (updating), you can look in MSsubscription_articles(or look for the presence of the subscription updating triggers against the table)
对于事务复制(更新),您可以查看MSsubscription_articles(或针对表查找订阅更新触发器的存在)
For merge replication, you can look in sysmergearticles, but you'd also have to look in sysmergesubscriptionsto determine that you're on the subscription side.
对于合并复制,您可以查看sysmergearticles,但您还必须查看sysmergesubscriptions以确定您在订阅端。
回答by Rksh001
Go to the subscriber database check for the table dbo.MSreplication_subscriptions. If the database is subscriber, you will find this table. Also, to find out articles use this in the subscribeddatabase
转到订阅者数据库检查表dbo.MSreplication_subscriptions。如果数据库是subscriber,您将找到此表。另外,要查找文章,请在subscribed数据库中使用它
SELECT publisher,Publisher_Db,publication,article
FROM dbo.MSreplication_objects
回答by pacreely
I used Damien the Unbeliever's idea(+1) to produce this code that worked for me
我使用Damien the Unbeliever 的想法(+1) 来生成对我有用的代码
SELECT DISTINCT
ot.object_id
,ot.schema_id
,r.publisher
,r.publisher_db
,r.publication
,r.article
FROM
dbo.MSreplication_objects R
INNER JOIN sys.objects so ON r.object_name = so.name AND so.type = 'P' --stored procedures
INNER JOIN sys.sql_dependencies dp ON so.object_id = dp.object_id
INNER JOIN sys.objects ot ON dp.referenced_major_id = ot.object_id --objects
AND r.article = ot.name
回答by Marian
Simplest way would be to create a linked server to the main server and query the table [distribution].[dbo].[MSarticles].
最简单的方法是创建一个链接到主服务器的服务器并查询表[distribution].[dbo].[MSarticles]。
select * from [distribution].[dbo].[MSarticles]
select * from [distribution].[dbo].[MSarticles]
回答by Ben Thul
Take a look at DATABASEPROPERTYEX. It has an 'IsSubscribed' option that should do what you want it to do.
看看 DATABASEPROPERTYEX。它有一个“IsSubscribed”选项,可以做你想做的事。

