Question

This may sound a little challenging but I think it can be done.

I want to create a script that will copy the table structure from Database1 (testing) onto Datbase2 (live). I know you could just do a simple copy from Database1 to Database2 but I want to retain the data Database1, I don't want it to be copied over.

Both databases will have almost the same table structure but Database1 is the the newer one so some tables may have an extra column or two and these columns are nullable so no issue. Also there may be new tables on Database1 which are not on Database2 so these will simply be copied over.

Is this possible to do?

Was it helpful?

Solution

Firstly you want to create a schema update script. There are a number of ways you can do this but the easiest are done automatically. Look for :

1) Visual Studio Schema Compare

2) Redgate SQL Compare

You can then use the same tools to perform data comparisons and generate a data update script.

OTHER TIPS

You could use c#. Just simply use string builder and with halp system schema you can create a null structure in new db. And then with the help of bulk copy you can copy data....if you want full code ask me..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top