SQL 编写发布脚本后服务器合并复制和某些表上的垂直分区
SQL Server merge replication and vertical partitioning on some tables after scripting of a publication
我们有一个数据库,我们在此期间根据 adding/removing 文章、出版物中复制文章的列进行了更改。现在,当我们编写该出版物的脚本时,我们有几行代码告诉我们垂直分区有问题,如下所示:
exec sp_addmergearticle @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @source_owner = N'dbo', @source_object = N'Customer_DELETE_LOG', @type = N'table', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000C034FD1, @identityrangemanagementoption = N'none', @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = N'', @vertical_partition = N'true', @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0, @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'true', @partition_options = 0
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_DATE', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_USER', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'COLUMN_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'ROW_ID', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'ROW_DELETED_VALUE', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'STATEMENT', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'PROCESSED', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'BATCH_ID', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'SERVER_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'APP_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'rowguid', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
GO
注意这里 @vertical_partition = N'true' 还要注意我们从不做任何垂直分区,至少不是故意的。
现在真正的问题是当 table 中有一些计算列时,这些计算列位于 table/article 脚本(包括垂直分区)的开头,处理将跳过那些专栏!因为这些列在其引用列之前添加到复制项目中,因此它们将破坏 sp_mergearticlecolumn
语句。为避免这种情况(不检查 400 条语句中的每条语句),将 @vertical_partition = N'true'
替换为 @vertical_partition = N'false'
,然后 运行 全部替换。这会奏效。但是,当您尝试编写整个脚本时,那些垂直分区语句会再次出现!为什么?
再说一遍:
- 垂直分区的实际含义以及为什么 SQL 服务器将其添加到
复制脚本?
- 如何检查table是否被垂直分割?
谢谢
德扬
更新
我现在正在更深入地研究这个问题,并开始自己研究 table 并注意到以下内容:
一些 table 缺少一些索引,例如 1、2、3、5 -> 其中索引 4 的列可能在某个时间点被删除。这会导致这个吗?这会导致发布脚本程序认为这是一个分区 table 吗?如果是这样,则 Microsoft 开发人员没有正确完成此操作。
"what vertical partitioning actually means"
table 文章的垂直分区意味着只发布了特定的列,而不是 table 的所有列。
why does SQL Server add it to the replication scripts
很可能有 article/table 中的 deselected/dropped 列。
如果有 deselected/not 已发布的专栏,您能否检查文章属性?
在脚本方面,您可以通过使用@vertical_partition = N'false' 创建一篇文章并稍后使用@operation = N'drop' 一列来实现相同的目的
--no vertical partitioning, all columns of the table are published
exec sp_addmergearticle @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @source_owner = N'dbo', @source_object = N'Customer_DELETE_LOG', @type = N'table',
@description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000C034FD1, @identityrangemanagementoption = N'none', @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = N'',
@vertical_partition = N'false', @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0, @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'true', @partition_options = 0;
--drop/deselect one column from the article
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_USER', @operation = N'drop', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1;
GO
--if you script the publication anew, it will have article @vertical_partition = N'true' and all columns @operation = N'add' except for the LOG_USER column (which is excluded from publication and does not appear in the script at all)
我们有一个数据库,我们在此期间根据 adding/removing 文章、出版物中复制文章的列进行了更改。现在,当我们编写该出版物的脚本时,我们有几行代码告诉我们垂直分区有问题,如下所示:
exec sp_addmergearticle @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @source_owner = N'dbo', @source_object = N'Customer_DELETE_LOG', @type = N'table', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000C034FD1, @identityrangemanagementoption = N'none', @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = N'', @vertical_partition = N'true', @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0, @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'true', @partition_options = 0
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_DATE', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_USER', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'COLUMN_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'ROW_ID', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'ROW_DELETED_VALUE', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'STATEMENT', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'PROCESSED', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'BATCH_ID', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'SERVER_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'APP_NAME', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'rowguid', @operation = N'add', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1
GO
注意这里 @vertical_partition = N'true' 还要注意我们从不做任何垂直分区,至少不是故意的。
现在真正的问题是当 table 中有一些计算列时,这些计算列位于 table/article 脚本(包括垂直分区)的开头,处理将跳过那些专栏!因为这些列在其引用列之前添加到复制项目中,因此它们将破坏 sp_mergearticlecolumn
语句。为避免这种情况(不检查 400 条语句中的每条语句),将 @vertical_partition = N'true'
替换为 @vertical_partition = N'false'
,然后 运行 全部替换。这会奏效。但是,当您尝试编写整个脚本时,那些垂直分区语句会再次出现!为什么?
再说一遍:
- 垂直分区的实际含义以及为什么 SQL 服务器将其添加到 复制脚本?
- 如何检查table是否被垂直分割?
谢谢 德扬
更新
我现在正在更深入地研究这个问题,并开始自己研究 table 并注意到以下内容:
一些 table 缺少一些索引,例如 1、2、3、5 -> 其中索引 4 的列可能在某个时间点被删除。这会导致这个吗?这会导致发布脚本程序认为这是一个分区 table 吗?如果是这样,则 Microsoft 开发人员没有正确完成此操作。
"what vertical partitioning actually means"
table 文章的垂直分区意味着只发布了特定的列,而不是 table 的所有列。
why does SQL Server add it to the replication scripts
很可能有 article/table 中的 deselected/dropped 列。 如果有 deselected/not 已发布的专栏,您能否检查文章属性?
在脚本方面,您可以通过使用@vertical_partition = N'false' 创建一篇文章并稍后使用@operation = N'drop' 一列来实现相同的目的
--no vertical partitioning, all columns of the table are published
exec sp_addmergearticle @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @source_owner = N'dbo', @source_object = N'Customer_DELETE_LOG', @type = N'table',
@description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000C034FD1, @identityrangemanagementoption = N'none', @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = N'',
@vertical_partition = N'false', @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0, @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'true', @partition_options = 0;
--drop/deselect one column from the article
exec sp_mergearticlecolumn @publication = N'secspe_pub', @article = N'Customer_DELETE_LOG', @column = N'LOG_USER', @operation = N'drop', @force_invalidate_snapshot = 1, @force_reinit_subscription = 1;
GO
--if you script the publication anew, it will have article @vertical_partition = N'true' and all columns @operation = N'add' except for the LOG_USER column (which is excluded from publication and does not appear in the script at all)