I want to have a version of my db that contains all of data from first to now. If I use sql server replication, can I force that to ignore delete operation for replication?
views:
86answers:
2
+2
A:
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:
- 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? - 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.
van
2010-02-22 08:43:51
I have a db with 400 tables. I can't put trigger on every table.
masoud ramezani
2010-02-22 09:21:40
I do not think that the number of tables is limiting your usage of triggers. With little script you can create those triggers automatically. But this is more the question of your design. There is issue with logical delete in general: you might have FK constraint from "alive" table/row to a logically deleted one, which should not happen. But can you maybe elaborate on what you are trying to achieve with this kind of replication?
van
2010-02-22 10:23:26
If you do not like triggers on your PROD database, whey don't you have them only on the REPLICA? so that instead of DELETE you either do nothing or mark those as deleted.
van
2010-02-22 10:24:29
+1
A:
Not a common scenario, see if this can help: http://www.eggheadcafe.com/software/aspnet/35648651/disable-delete-on-transac.aspx
p.marino
2010-02-22 08:45:09