Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to copy data between two tables row by row

$
0
0

Hi All,

I have three tables TableA and TableB and TableC

I wanted to write a stored procedure to copy data row by row from TableA to TableB and then update TableC by replacing any record that has the old id (before copying) to the new id after copying the data.

here is the steps 

iterate throw all the rows in tableA ( probably with a foreach)

in each iteration we will do the following:

Get current ID (identity) for each record in TableA ( will call it @oldID)

Insert the row in TableB

Get the new ID for the row from TableB will call it (@NewID)

find rows in tableC that has the (@oldID)

replace all ids in tableC with @oldID to @NewID

Thanks in advance



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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