dheerajjuneja

Rename database files both physical and logical, MS SQL SERVER 2005

Steps involved in renaming the database:

  1. Rename the logical files
  2. Detach the database
  3. Rename the physical files
  4. Attach the database as the new database, using the renamed files

Steps to rename the logical files:

a. Open the database properties, and select the “Files” tab from left:

Renamedb_step3

b. Place the cursor in the cell, under the column “Logical names” and type the new name for both MDF and LDF files:

Rename logical files - MS SQL SERVER 2005

c. Press “ok” to close this screen. The logical files are now renamed.

Steps to detach the database:

a. Right click on the databse, from “Tasks” menu, select “Detach”

Detach database - - MS SQL SERVER 2005

b. Press “Ok” on the screen that appears.

Detach database - MS SQL SERVER 2005

Steps to rename the physical files:

a. Check where the files are stored from the “properties”->”Files” tab and rename the files using windows explorer.

Renamedb_step7

Steps to Attach the database as the new database, using the renamed files

a. Issue the command:
sp_attach_db <new_dbname>,<new physical MDF name with path>,<new physical LDF name with path>

sp_attach_db usage

That’s it, now check the databases list and you should have the new database ready with new physical file names.

Not necessarily you have to rename the databases, in case you have a mismatch between the database name and the physical file/logical file names, you can use the same steps to get this issue sorted.

If you are facing any major issues with SQL Server, please feel free to contact us: http://www.loginworks.com

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Comments »

 
 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>