Our users want to refresh a QA database from production but want two tables (lets call them T1 and T2) to retain the original QA data. So I copied two tables from QA (DB1) to a temp QA database (DB2). Then refreshed DB1 from production. After the refresh, I want to overwrite T1 and T2 data from DB2 to DB1 so it can contain pre-refresh QA values.
I have done the following:
Use
select * INTO D1.dbo.T1 FROM D2.dbo.T1Then refreshed D1 from prod
Then truncate T1 with the following step:
SELECT COUNT(*) AS BeforeTruncateCount FROM T1; GO TRUNCATE TABLE T1; GO SELECT COUNT(*) AS AfterTruncateCount FROM T1; GONow when I go back to copy data from D2.T1 to D1.T1, I get the error that there is already an object named T1 in the database.
Should I drop the table and copy?
Or is there any better method for the whole procedure?





*) if there is an indentity field in the table - those values can't just be "copied." – Conrad Dec 02 '15 at 16:17