Sql server EXEC sp_更改所有项目的合并项目
是否有一种方法可以同时更改复制中所有项目的属性 因此,不是:Sql server EXEC sp_更改所有项目的合并项目,sql-server,stored-procedures,replication,Sql Server,Stored Procedures,Replication,是否有一种方法可以同时更改复制中所有项目的属性 因此,不是: EXEC sp_changemergearticle @publication = 'MyPublication', @article = 'MyArticle', @property = 'published_in_tran_pub', @value = 'true'; EXEC sp_changemergearticle @publication = 'MyPublication', @article = 'MyAr
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = 'MyArticle',
@property = 'published_in_tran_pub',
@value = 'true';
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = 'MyArticle1',
@property = 'published_in_tran_pub',
@value = 'true';
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = 'MyArticle2',
@property = 'published_in_tran_pub',
@value = 'true';
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = 'MyArticle3',
@property = 'published_in_tran_pub',
@value = 'true';
我想为一个查询中的所有文章更改\u tran\u pub中的@published\u属性。比如:
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = 'ALL ARTICLES',
@property = 'published_in_tran_pub',
@value = 'true';
因此,我想通过一条语句更改所有文章的@published_in_tran_pub属性
提前谢谢好的
我可能又弄错了——但似乎我不知道什么比你更想称之为存储过程——你可以循环浏览你的文章集,并将它们传递给存储过程
-- I presume you can get a list of distinct Articles - you dont have to use
-- a tmp table if they already exist - use that table instead
SELECT DISTINCT ROW_NUMBER() OVER (ORDER BY Article) as Row_ID,
Article
INTO #Tmp
FROM MyArticleTable -- Dont know what this is called
WHERE publication = @publication -- only pick the articles you want to use for this sproc call
DECLARE @i int = 1
DECLARE @currentArticle varchar(max)
WHILE @i <= (SELECT COUNT(*) FROM #Tmp)
BEGIN
SET @currentArticle = (SELECT Article FROM #Tmp WHERE Row_ID = @i)
EXEC sp_changemergearticle
@publication = 'MyPublication',
@article = @currentArticle,
@property = 'published_in_tran_pub',
@value = 'true'
SET @i = @i+ 1
END
看起来不错,虽然还不起作用。它一直在说“正在执行查询”-现在已经有5分钟了..要获得我可以查询的所有文章的列表:从SYS.tables中选择name,where is_merge_published=1是的,循环方法不会很快-你需要做多少次迭代?你可以在它上面运行一个探查器,看看是否有任何索引或你可以做的任何事情-将sys.tables中的数据放到sys.tables one中不存在的另一个表中可能会更快,并看看是否有任何索引策略可以帮助它工作-非常好,我添加了'SET@I=@I+1'-非常感谢!是的,很抱歉,我只是不太明白你最初想要什么。为接受答案干杯