Moving a Database from SQL Server 2005 to SQL Server 2008 in Three Steps

by Jayaram Krishnaswamy | February 2008 | .NET Microsoft

There are several options if one wishes to move a database from a SQL Server 2005 to SQL 2008 Server. First of all there is a 'Copy Database Wizard' in SQL 2008 Server which is meant for transferring a database from any version of SQL Server 2000 and above to 2008 version. In the other option the database will be copied using the SQL Server Management Program for which the source database need not be stopped. However this is slower than the previous method and would also require the SQL Server Agent since a package has to be run.

An option which works without too much hassles is manually detaching and attaching the database/log files. In this step-by-step (really two steps) tutorial by Jayaram Krishnaswamy, this simple procedure is described. If you are just interested in taking a small database from 2005 to 2008 server the author strongly recommends this procedure.

(For more resources on Microsoft, see here.)

Introduction

There are several options if one wishes to move a database from a SQL Server 2005 to SQL 2008 Server. First of all there is a 'Copy Database Wizard' in SQL 2008 Server which is meant for transferring a database from any version of SQL Server 2000 and above to 2008 version. This Wizard can operate in two ways. In the first option it can attach a database (even one on the network) and uses the SQL 2008 SQL Server agent. The Copying of the database is implemented by an Integration Services package to run as a SQL Server Agent job that is scheduled to run immediately or according to some configurable schedule. This will therefore depend on correctly configuring the SQL Server Agent. In order to use the attach / detach process, the remote server will be stopped and if the database / log files are on a shared drive they are correctly brought in by the wizard. In the other option the database will be copied using the SQL Server Management Program for which the source database need not be stopped. However this is slower than the previous method and would also require the SQL Server Agent since a package has to be run.

An option which works without too much hassles is manually detaching and attaching the database/log files. In this step-by-step (really two steps) tutorial, this simple procedure is described. If you are just interested in taking a small database from 2005 to 2008 server the author strongly recommends this procedure.

Interested readers may also want to read my other popular article Moving Data from SQL Server 2000 to SQL Server 2005

Step 1: Detaching the Database

Highlight the database you want to transfer in the Databases node in the SQL Server Management Studio as shown in the next figure. Right click this database as shown and click on Detach... Make sure the database is running (notice the green arrow for HodentekSQL Express which is a junior version of SQL 2005).

Moving a Database from SQL Server 2005 to SQL Server 2008 in Three Steps

This brings up the Detach Database window as shown. Place a check mark for 'Drop' as shown and click on OK. This removes the 'Pubs' node from the Databases folder in the SQL Server Management Studio (You may need to attach it again). With this accomplished you can physically move the files or do what you want with them.

Moving a Database from SQL Server 2005 to SQL Server 2008 in Three Steps

Step 2: Copy the DATA / LOG Files

Copy the pubs.mdf and pubs.ldf files to a location on the C: drive of the machine on which SQL 2008 Server is installed.

Sign up for a Packt account to see the rest of this article

Now that you've read a few articles, you might want to consider signing up for a Packt account. It takes a matter of seconds, will give you access to all the articles on PacktPub.com, and once you've signed up you'll be returned here to carry on reading your article.

Furthermore, you'll gain access to nine free ebooks, and be offered a free trial of PacktLib, Packt's online library. Simply enter your details here, or log in to your existing account.

Log in

...or register

Superb article! by
Thanks for clear description and snapshots!
Thank you so much by
Thank you so much
Error message when Migrating Databases from sql 2005 to sql 2008 by
windows module cannot execute because the system date / time settings on the machine do not match the settings on the server
Stored Procedures did not move by
I did exactly what has been described above and moved it successfully to 2008. But Stored procedure are missing! I had to backup 2005 DB and restore it in 2008 and it worked for me as a charm (all SPs are in)! Well, why to do it complicated way if is it possible do it simply through a backup?
detached now files gone? by
I detached the db exactly like described. Also with that drop option which actually already freaked me out a bit. now the db is dissappeared from the studio. also in the DATA directory the mdf files are gone. WTH! i'm going nuts now
Moving sql server 2005 database to sql server 2008 by sayeed ahmed
I have database on sqlserver 2005 what i did i have taken a back up copy example mydata.bak file Now on sqlserver 2008 I have create a new database and right click and then restore database Is that correct way I have done , please correct me if I am wrong.
i detaches the database now by
i detaches the database now canot find the files - you say Copy the pubs.mdf and pubs.ldf files to a location on the C: drive of the machine on which SQL 2008 Server is installed. were do the files go?? i detached the database now it is gone??
Watch out for different sector size by
All the above works great unless you are moving to a disk that has a different physical sector size - in which case you won't be able to use detach/attach, or backup/restore. Not sure if the "Copy Database" wizard will let you
Works Great. Thanks a bunch!! by
Works Great. Thanks a bunch!!
users.... by
You will have troubles with the attached users if you don't remove them from the database first...

Post new comment

Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z