开发者

Is there a way to force replication that replicate only inserted and updated data?

I want to have a version of my db that contains all o开发者_StackOverflow社区f data from first to now. If I use sql server replication, can I force that to ignore delete operation for replication?


I am not aware of such feature.

And I would be surprised if one exists out of the box. What if instead of UPDATE one does DELETE and INSERT? Your target database will not be able to handle such change because it will not delete a row with some unique identifier (column value) XXX, and then will try to insert a new one with this identifier, resulting in a unique key violation.

EDIT-1: If what you want is the only-recent database in production and the whole database for audit, then maybe you should try different solution:

  1. Logical Delete and a View: you change your DELETE logic (either by changing the DELETE command, or by using INSERT OF trigger) to only mark rows as deleted. Then you create a view that basically wraps your table but filters only those that are not deleted. Run all your SELECT/INSERT/UPDATE queries against this view instead. At the end also in your current solution you do mark "deleted" records as deleted somehow, right?
  2. Audit tables: keep your history also in your main database, but in AUDIT (shadow) tables. Again you can do this with AFTER triggers almost non-intrusively.


Not a common scenario, see if this can help: http://www.eggheadcafe.com/software/aspnet/35648651/disable-delete-on-transac.aspx


Yes, you can. If you use Transactional Replication, you define what is done for updates, deletes and inserts on table articles that you publish.

EDIT to add more detail:
So, when creating a new Transactional Publication, under the Articles step (Figure 1), you can select all tables and "Set Properties of All Table Articles". The section under "Statement Delivery" (Figure 2) offers options on "delivery formats" for INSERT, UPDATE, and DELETE statements. You can set the format to "Do not replicate DELETE statements" or, for example "Call <stored procedure>", which can call a stored proc that sets a flag on each row that has been deleted on the Publisher.

Figure 1

Is there a way to force replication that replicate only inserted and updated data?

Figure 2

Is there a way to force replication that replicate only inserted and updated data?

With reference to Hilary Cotter's answer on MSDN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜