Quantcast
Channel: SQL Server Manageability forum
Viewing all articles
Browse latest Browse all 1519

Merge Confusion Help please.

$
0
0

Ok so i have an ETL process that right now im Importing 5 days worth of data and then putting that in a temp table, deleting from the production table where the record exists in the temp table and then inserting everything from the temp table into production table.  May seem weird but this is the way i need to do this.  

However i understand Merge might be able to do this better.  So i wrote a statement and im afraid to run it as i want to make sure its right.

Merge Prod_Table As A Using Temp_Table As B
On A.Col1= B.Col1
When Matched Then Delete
When Not Matched Then Insert
(List of columns)
Values
(List of columns);

So my questions are 1, does this delete everything from prod and insert from temp at the same time which means that the records it deleted do not get re-inserted?

2 - Is it doing what i want?

3 - Can i make this easier to replicate in the future by involving an insert into Prod_Table select * From temp_table rather than listing out all the columns each time?



Viewing all articles
Browse latest Browse all 1519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>