DB_AM DB_AM - 28 days ago 8
SQL Question

The data is overwritten in SQL Server 2008

I have a table that keeps records only for 3 months then overwrite these data.
I want to keep all the data so I made a merge replication between this database and another database but the data is still overwritten in both databases (publisher and distributor)

What is the best way to solve this?

Answer

Use this:

INSERT INTO DB2..T1 (column1,column2,column3)
SELECT column1,column2,column3
FROM DB1..T1 As Src
WHERE NOT EXISTS (
   SELECT *
   FROM DB2..T1 As Tgt
   WHERE Tgt.ID = Src.ID
   )