Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to attach .mdf and .ldf file of an existing database with some change and different name.When i am attaching them , sql server automatically converting them to their original names(existing data base name) and giving out an error .

share|improve this question

migrated from Jan 13 '10 at 9:13

This question came from our site for professional and enthusiast programmers.

are you trying to rename the database or specifically just the MDF and LDF files. If just the files the answer from Murph is correct, Backup, Detach, modify, attach. – Dan Jan 13 '10 at 9:17

As far as my understanding goes that's kind of the way it is with detach and attach - this is both good and bad - good because database is substantially self contained within those files as it contains its own metadata notionally making moving a database easy, bad because there are scenarios where this isn't what one wants.

There are two obvious ways to deal with this depending on exactly what you are able to do:

  1. The first is to use backup and restore instead of detach/attach - at this point you can make quite a lot of changes.
  2. Second is to attach the database to a distinct server instance, rename it there and then detach and attach to the orignal instance.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.