SQL Server 2008 R2: Move Database Files to a New Location

I am in the process of decommissioning an old server. This server performed several roles, but was primarily our SQL Server. In moving a couple of the databases, they did not end up exactly where I wanted due to the process used to move them to the new server. I did some quick research and came up with this method to move the databases into their final location.

SOLUTION

1)  Look at the Database Properties => Files

2)  Note the Logical Name & File Name

3)  Take Database Offline

4)  Move the MDF & LDF files to the new location

5)  Make sure permissions and ownership are configured correctly

Permissions:

SERVERNAME\OWNER RIGHTS = Full Control

SERVERNAME\Administrators = Full Control

SERVERNAME\SQLServerMSSQLUser$SERVERNAME$MSSQLSERVER = Full Control

Ownership:

DOMAIN\SQLSERVICEACCOUNT

6)  Run the following SQL Script:

ALTER DATABASE dbname
MODIFY FILE (
NAME ='logicalname'
,FILENAME = 'E:\MDF\dbname\filename.mdf'
)

ALTER DATABASE dbname
MODIFY FILE (
NAME ='dbname_log'
,FILENAME = 'F:\LDF\dbname\filename_log.ldf'
)

7) Bring the database back online.

Download My Script (Right Click and choose Save Link As…)

Advertisements
This entry was posted in SQL Server 2008 R2 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s