views:

28

answers:

3

I have a database project that goes through iterations (only one so far) and I need to deploy a testing version to a live server. I'm not sure how to go about this.

I can make all the changes in a copy and then remake those changes in the live version. That doesn't make sense.

Is there a way to change a server name to an existing server? What's the best practice for this scenario?

+1  A: 

With a Visual Studio Database Project, you should be able to have as many database connections defined as you like. When you go run your scripts, you can pick an menu option called "Run On...." and then pick which server connection to run those scripts on.

alt text

Just make sure the database name is the same for both instances, or make sure that you do not specify USE (database) at the top of all your scripts, if the database names are different from target to target.

marc_s
I'm making changes on the database. I can change the connection in a VS project. I need to know how to deploy the development version of the 'server'
Chris
@Chris: can you connect to both servers at the same time? In that case, I'd heartily recommend Red-Gate SQL Compare and SQL Data Compare to handle database synchronisation - http://www.red-gate.com/products/sql_compare/index.htm
marc_s
@marc_s: I don't have the luxury of special tools, I just thought there was a standard strategy for this type of situation
Chris
I didn't know VS had a database project tool that could manage this stuff. I am very thankful. I've been doing all this in t-sql on managment studio. Thanks much
Chris
A: 

Maybe I'm misunderstanding the question, but I don't see how you could just swap the databases. If you make a development version of a database and update the schema, you must surely run some tests and update the data. You can't just make that the development database now because it's full of test data.

What you need to do is run a tool that compares the old schema to the new schema and then apply these changes to the production database. There are tools out there on the market to do this. Failing that, you could dump the old and new schemas, run them through an ordinary file compare to get the differences, and then build an update script out of that.

On my present project we use what I think is a terrible practice: We keep a hand-maintained script of schema updates for each version, and every time someone makes a change they're supposed to update this script. Every now and then someone makes a mistake and we have to scramble to figure out what went wrong. Like we just had a problem deploying to our user acceptance test because someone updated the create statement for a new table to include a foreign key to another new table ... not realizing that the table being referenced was created until further down in the script. It worked fine it test because the tables were created in an order that made it work.

My conclusion is you're much better off to just make changes to the schema on the fly, then when you're done, run an automated compare to generate the ALTER statements.

By the way, on a project I worked on a few years ago, for a desktop application where each customer had their own copy of the database, we put in what I thought was a very nice feature: Every time the program started up, it compared the schema of the database to what it thought it ought to be, and if they didn't match, it automatically updated it. So when they installed a new version, it just automatically updated the database the first time they ran it.

Jay
the 'automated compare' scripts, how is this done?
Chris
You should alwawys do all database changes in scripts and save the scripts in source control. Then just like other code, you can easily deploy. Relying on a compare tool is a poor practice.
HLGEM
@HLGEM: Well, obviously I disagree. If you build your update scripts manually, sooner or later you will make a mistake. You'll apply an update to a table but forget to put it in the script. Or you'll change an attribute of a field and so update the original "create" statement, but you'll mistype it. Etc. A compare program should be guaranteed to give correct results. If you want to save the scripts generated by the compare program in your archive for historical reasons, cool. Just because a technique is more work does not automatically make it the right way.
Jay
Since we do not allow devs to make any changes except with a script, we don't have issues with that.They don't have prod rights and they know they have to do the script for the work to get promoted, we don't have problems with developers not scripting out everything. Compare programs have issues, too. Relying on them increases your chances of accidentally promoting something that isn't ready. There is no reason to treat SQL code any differently than other code. Devs don't forget to put their other code in source control, so it is there for moving up to prod do they?
HLGEM
But if you have to edit your script, then in order to test it you need to go back to a database before the original script was run. If you don't, then you can't run the entire script because it will fail when trying to re-add the fields or tables that have already been added or dropping the ones that have already been dropped. I suppose you could keep cloning off an old database. But around here our database is big enough that that takes hours, and who wants to wait for that to make one simple little change? (continued ...)
Jay
(continued) I suppose you could keep a tiny database for testing that could be easily cloned and re-updated, but in many cases that's not practical, you want a large set of data for testing, to insure that you cover all combinations and that performance doesn't become unacceptable at realistic file sizes. How do you handle these issues?
Jay
A: 

In the first place, you should have scripts already written for the changes you made. They should be in source control. No changes ever should be made to database structure without a script and versioning.

Since you don't appear to have what you should have to deploy, then you need to tool to check the differences between the datbases. Reg-Gate's SQl compare is the one to buy.

Be careful of simply using the tool without thinking, there may be changes in dev you are not yet ready to promoote to prod. Read through the scripts before running them.

Also you may need SQL DataCompare to run against any lookpup tables you have to see if new values have been added in dev that need to go to prod. Again these inserts should have been scripted and in source control and then deploying is simple.

HLGEM
I know I'm going to sound stupid but where is are these 'scripts' and 'changes' being done. I built this tool directly from 'Management Studio'
Chris