views:

203

answers:

5

Say I have a website and a database of that website hosted locally on my computer (for development) and another database hosted (for production)...ie first I do the changes on the dev db and then I do the changes to the prod DB.

What is the best way to transfer the changes that I did on the local database to the hosted database?

If it matters, I am using MS Sql Server (2008)

+1  A: 

We do this in the (Ruby on) Rails world by writing "migrations," which capture the changes you make to the DB structure at each point. These are run with a migration tool (a task for rake), which also writes to a DB table so it knows whether a particular migration has been run or not.

You could make a structure like this for your dev platform (.Net?), but I think that in other answers to this question people will suggest available tools for handling database versioning in your development platform, or perhaps for your specific DB.

I don't know any of these, but check out this list. I see a lot of pay things out there, but there must be something free. Also check this out.

Yar
+1  A: 

I migrate changes via change scripts written by developers when they have tested/verified their changes. (The exception being moving large data.) All scripts are stored in a Source control system. and can be verified by DBAs.

It is manual, sometime time consuming but effective, safe and controled process.

Databases are too vital to copy from dev.

There are tools to help create/verify these scripts. See http://www.red-gate.com/ I have used their tools to compare 2 databases to create scripts. Brian

+1  A: 

The correct way to do this with Visual Studio and SQL Server is to add a Database Project to the web app solution. The database project should have SQL files that can recreate the entire database completely on a new server along with all the necessary tables, procedures users and roles.

That way, they are included in the source control for all the rest of the code as well.

There is a Changes sub-folder in the Database Project where I put the SQL files that apply any new alterations or additions to the database for subsequent versions.

The SQL in the files should be written with proper "if exists" blocks such that it can be run safely multiple times on an already updated database without error.

As a rule, you should never make your changes directly in the database - instead modify the SQL script in the project and apply it to the database to make sure your source code (the SQL files) is always up to date.

Ron

Ron Savage
+1  A: 

If the changes are small, I sometimes make them by hand. For larger changes, I use Red Gate's SQL Compare to generate change scripts. These are hand-verified and run in the QA environment first to make sure they don't break anything. For large changes, we run a special backup prior to making the change both in QA and in production.

tvanfosson
A: 

We used to use the approach provided by Ron. It makes sense for a big project with dedicated team of DBAs. But if you do not have a dedicated developers who write code only for DB this approach is time and resource expensive.

The approach to use RedGate DB compare is also not good. You still have a do a lot of manual work you can skip some step by mistake.

It needs something better. This is was the reason why we built the "Agile DB Recreation/Import/Reverse/Export tool" The tool is free.

Advantages: your developers use any prefered tools to develop DEV DB. Then they run the DB RIRE and it makes reverseengeniring DB (tables, views, stor proc, etc) and export data into XML files. XML files you can keep in the any code repository system.

And the second step is to run DB RIRE one more time to generate difference scripts between structure and data in XML files and in Production DB.

Of course you can make as much iterations as you need.

Roman Podlinov