简体   繁体   English

避免在SQL Server中复制DELETE语句

[英]Avoid replicating DELETE statements in SQL Server

Consider the following scenario: 请考虑以下情形:

One PC is running an Access database. 一台PC正在运行Access数据库。 An old legacy script will copy over all the contents from this Access database to a SQL Server (A) over LAN. 旧的旧脚本将通过LAN将所有内容从此Access数据库复制到SQL Server(A)。 But before it does this, it will delete all contents from the destination database, so it doesn't have to deal with existing records. 但是在执行此操作之前,它将删除目标数据库中的所有内容,因此它不必处理现有记录。 Previously existing records are never altered. 以前的现有记录永远不会更改。

On the SQL Server (A), replication is defined and it acts as a publisher. 在SQL Server(A)上,定义了复制,并且复制充当发布者。 It will publish/replicate the data to SQL Server (B) over WAN. 它将通过WAN将数据发布/复制到SQL Server(B)。

This all works very well, but the only problem I'm facing is when there's a problem during the copying of contents to SQL Server (A), SQL Server (B) will be empty or missing records, even the records that were replicated a long time ago. 这一切都很好,但是我面临的唯一问题是将内容复制到SQL Server(A)时出现问题,SQL Server(B)将为空或丢失记录,即使是已复制的记录也是如此。很久以前。

There are two solutions I've already considered: 我已经考虑了两种解决方案:

  • Adapt the legacy script to only copy over new records, since the updates are incremental of nature. 调整旧脚本以仅复制新记录,因为更新本质上是增量的。
  • Configure the replication to avoid DELETE statements. 配置复制以避免DELETE语句。

The first solution is in this scenario not possible. 在这种情况下,第一种解决方案是不可能的。 The application is closed-source, and there's really nothing we can change. 该应用程序是开源的,我们没有任何改变。

The second solution would be ideal, but (A) would try to replicate records that already exist on (B), and I'm not quite sure how to handle that. 第二种解决方案是理想的,但是(A)会尝试复制(B)上已经存在的记录,但我不确定如何处理。

Surely there's a sound concept to this problem, I just haven't figured it out yet.. 当然,这个问题有一个合理的概念,我只是还没有弄清楚。

In SSMS go to Replication -> Local Publications and right click on your publication and select Properties. 在SSMS中,转到复制->本地发布,然后右键单击发布,然后选择属性。 In the Publication Properties window click on 'Articles' and select the relevant article. 在“出版物属性”窗口中,单击“文章”,然后选择相关文章。 Go to "Article Properties" and select "Set Properties of Highlighted Table Article". 转到“文章属性”,然后选择“设置突出显示的表文章的属性”。 In the article properties window, change the "DELETE delivery format" to "Do not replicate DELETE statements". 在商品属性窗口中,将“删除交付格式”更改为“不复制DELETE语句”。 After the change click OK and you will see a prompt. 更改后,单击确定,您将看到提示。 As the article property has been changed the subscriptions need to be reinitialized. 由于商品属性已更改,因此需要重新初始化订阅。 Click "Mark for Reinitialization" which causes the snapshot to be applied to the subscriber. 单击“标记为重新初始化”,这会将快照应用到订阅服务器。 In SSMS, navigate to Replication and right click and select "Launch Replication Monitor". 在SSMS中,导航到“复制”,然后右键单击并选择“启动复制监视器”。 Go to your publication and click View Details to see the snapshot progress. 转到您的出版物,然后单击查看详细信息以查看快照进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM