Updating SQL Server 2005 Database with new records from another database

StackOverflow https://stackoverflow.com/questions/23668629

  •  23-07-2023
  •  | 
  •  

سؤال

When I began with my project, I was just connecting to the networked server connection at work, so I decided to have a local copy of that database in my laptop (using the attach-detach method). The problem is that the database in our office is still being updated, and I created new tables in my local database (the data in my database is not updated, so I don't have the new records). How do I merge the changes in the database in our office (by merging the changes, I mean, how can I update their database to include the new tables I created and the new records being updated in their database)? If I will use the attach-detach method, they will have the new tables but the new records they created will not be saved.

If I'm being confusing, let's put it like this: To make this clear, let's name the database 'SQLDB'. Originally, there is only an 'SQLDB' at work, but I have to work on this project at home so I created an 'SQLDB' at home. There is an 'SQLDB' at work, and an 'SQLDB' at home. The 'SQLDB' at work keeps on being updated while the 'SQLDB' at home is not (so it doesn't have the new records), but the 'SQLDB' at home has two new tables. If I am to detach-attach the 'SQLDB' at home so that 'SQLDB' at work will also have the new tables, but the new records will be gone (because 'SQLDB' at home is not being updated). I want to have these changes merged (the new tables and new records) and save the final database for 'SQLDB' at work.

I hope I already made it clear. Any input will be appreciated. :)

هل كانت مفيدة؟

المحلول

Your best bet would be to use a set of update scripts - as described below:

  1. Get a latest version of the SHARED database.
  2. Restore this version to a LOCAL instance.
  3. Run the set of scripts to upgrade the SHARED database with your new Tables / data.
  4. Test that everything went ok.
  5. Run the same set of scripts on the SHARED database to update it.
  6. Repeat.

See this excellent blog post : http://blog.codinghorror.com/get-your-database-under-version-control/

And this discussion : Do you use source control for your database items?

And this tool: http://dbsourcetools.codeplex.com/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top