sean
sean

Reputation: 11634

Backing and restoring SQL Server data to changed database structure

The scenario is this. I have a SQL Server database online that I am demoing an application. During development, I have added extra fields, modified field types, changed keys and added some new tables locally.

What's the best way for me to update the online database with the new structure and not lose the data? The database is a SQL Server 2005 one.

Upvotes: 0

Views: 151

Answers (5)

Jason Cono
Jason Cono

Reputation: 91

Download a trial of Red Gate SQL Compare, compare your two servers and you are done. If you do this often, it is well worth the $400, or get one of their bundles for a better bang for the buck.


And I do not work for Red Gate, just a happy customer!

Upvotes: 2

dkretz
dkretz

Reputation: 37655

  1. Make a copy of the existing database to copy from.

  2. Make another copy and alter it to your new schema. save DDL for reuse.

  3. Write queries that copy data from #1 to #2. Save the queries for reuse.

  4. Check the results.

  5. Repeat until done.

Upvotes: 0

hybo
hybo

Reputation:

This probably isn't of huge help retrospectively, but I always script all structural DB changes to my development database and then using a version number to determine the current version of the DB I can run the required scripts on the live DB, hence bringing it back in line at the same time as the new code is uploaded.

This also works for any content changes, for instance if the change in the underlying structure has an effect on the conent stored you can also write scripts to migrate the data accordingly.

Upvotes: 0

Adam Robinson
Adam Robinson

Reputation: 185663

Depending on what exactly you've done you may be able to get away with alter statements, though from the sounds of it (removing keys and whatnot) you're doing some heavy lifting that may make that a less-than-ideal solution. You should probably look into creating a maintenance plan or, better yet, a SQL Server Integration Services project in Visual Studio. You should be able to migrate the data in the existing database to a new one using those tools.

Upvotes: 0

Bravax
Bravax

Reputation: 10493

Write update scripts to modify your live database structure to the new structure, as well as inserting any data which is required.

You may find it necessary to use temporary tables to do this.

It's probably best if you test this process on a test environment, before running the scripts on the live environment.

Upvotes: 2

Related Questions