我们有一个SQL脚本,用于创建出版物及其文章,以及拉取订阅。这是非常基本的,因为我们没有明确地排除任何文章,而是将它们全部传递给订阅者(用于我们报告使用的查询的数据库,以防止对应用程序数据库的过度负载)。
作为设置发布文章的一部分的脚本循环遍历源数据库中的每篇文章和表,执行以下操作:
DECLARE @Ins nvarchar(255) = 'CALL sp_MSins_'+@articleSchema+@articleName
DECLARE @Del nvarchar(255) = 'CALL sp_MSdel_'+@articleSchema+@articleName
DECLARE @Upd nvarchar(255) = 'CALL sp_MSupd_'+@articleSchema+@articleName
exec sp_addarticle
@publication = @PublishName,
@article = @Joined,
@source_owner = @articleSchema,
@source_object = @articleName,
@type = N'logbased',
@description = null,
@creation_script = null,
@pre_creation_cmd = N'drop',
@schema_option = 0x00000000080350DF,
@identityrangemanagementoption = N'manual',
@destination_table = @articleName,
@destination_owner = @articleSchema,
@vertical_partition = N'false',
@ins_cmd = @Ins,
@del_cmd = @Del,
@upd_cmd = @Upd
我的问题在于@schema_option
存储过程的sp_addarticle
参数。
用于检查 0x00000000080350DF 的计算(按位或)值,并根据该脚本为表文章启用了以下选项:
**SCHEMA OPTIONS HERE ARE**
—————————————
0x01 Generates the object creation script (CREATE TABLE, CREATE PROCEDURE, and so on). This value is the default for stored procedure articles.
0x02 – Generates the stored procedures that propagate changes for the article, if defined.
0x04 – Identity columns are scripted using the IDENTITY property.
0x08 – Replicate timestamp columns. If not set, timestamp columns are replicated as binary.
0x10 – Generates a corresponding clustered index. Even if this option is not set, indexes related to primary keys and unique constraints are generated if they are already defined on a published table.
0x40 – Generates corresponding nonclustered indexes. Even if this option is not set, indexes related to primary keys and unique constraints are generated if they are already defined on a published table.
0x80 – Replicates primary key constraints. Any indexes related to the constraint are also replicated, even if options 0x10 and 0x40 are not enabled.
0x1000 – Replicates column-level collation
0x4000 – Replicates UNIQUE constraints. Any indexes related to the constraint are also replicated, even if options 0x10 and 0x40 are not enabled
0x10000 – Replicates CHECK constraints as NOT FOR REPLICATION so that the constraints are not enforced during synchronization
0x20000 – Replicates FOREIGN KEY constraints as NOT FOR REPLICATION so that the constraints are not enforced during synchronization
0x8000000 – Creates any schemas not already present on the subscriber
正如您所看到的,似乎应该为表项启用了用于启用非聚簇索引生成的0x40选项。
但是,启动快照代理后,生成快照并且日志阅读器代理执行其操作,如果我访问发布的属性,我可以看到对于表文章,设置“复制非聚集索引”设置为 false 。
有谁知道为什么没有为表格文章启用此选项?我一直试图解释technet上的文档:https://technet.microsoft.com/en-us/library/ms173857(v=sql.105).aspx但是没有发现为什么会忽略这个标志的原因。
我不能仅仅在管理工作室的属性对话框中更改选项,因为我们的产品不一定能直接访问客户端的SQL Server实例,但必须通过PowerShell从安装机器远程执行脚本,这个脚本就是一个。
提前致谢。
答案 0 :(得分:0)
索引视图的默认架构选项不包括聚簇索引。默认情况下,使用GUI设置文章时,仅复制索引视图的模式,而不复制索引。
要复制索引,可以更改sp_addarticle的脚本,并将@schema_option从0x0000000008000001替换为0x0000000008000051。