SqlBulkCopy with relationships

copy database sqlbulkcopy

Question

I need to somehow copy data from one database to another. I guess best will be SqlBulkCopy. Problem is that, my table Product have 5 more tables connected with ID of product. So product is connected with Product_picture (pictureID, productID), for example. Is there any way to copy Product and all other connected tables with ID (or Identity) from one database to another?

Popular Answer

Invoke bulk copy multiple times. Nothing of this is automated in the product, so you have to build this on your own.

Look into table valued parameters. They are much more flexible and offer reasonable performance for bulk jobs. It is probably fast enough.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why