SharePoint 2010 - Rename a Content Database

Tags: Administration, SharePoint 2010, SQL

A great question came up in class today:  "Can I rename a content database?"  Having never actually done such a thing, I took the time to give it whirl.  The scenario here is that the only thing that I wanted to change was the name of a content database.  I did not change any web applications, URLs, alternate access mappings, permissions, or anything else.  The database SharePoint had created for me was called "WSS_Content_awrffdojsfjds23409324" (something awful like that, at least) and I wanted to rename it to "WSS_Content_Contoso."  Again, nothing else in the SharePoint environment or configuration was changed.  Given that, the steps below worked just fine.  However, here are some things to be aware of before you go through the steps:

  • First things first, avoid renaming databases if possible.  Plan ahead and establish a proper naming convention for your content databases.
  • These steps apply only to content databases.  These steps may not work for configuration or service application databases.
  • Do this at your own risk.  I've performed these steps a few times in a virtual environment without any real risk of breaking my development SharePoint environment.  They may work differently for you; it depends on your environment.
  • Re-read number 3 above and be sure to fully test this on your own until you're comfortable with the steps involved and have ensured that it works.
  • Be sure to document your steps so they can be repeated if necessary in the future.
  • This applies to SharePoint 2010 and has not been attempted in SharePoint 2007.

Now that you've read my wonderful disclaimers, here are the steps that worked for me in my development environment.

  • In Central Administration, take the content database offline.
  • In Central Administration, remove the content database from SharePoint.  You'll get a warning here that any sites in that content database will no longer be available in SharePoint.  While that is true, it does not mean that you're deleting sites; the sites and all their data will remain in the content database.
  • In SQL Server, detach the database.  During this process, it may be necessary for you to also drop all existing connections to the database.
  • In SQL Server, re-attach the same database.  During this process, you should see an "Attach as" column in the upper table; it's here that you can change the name of the database, so call it what you want.  Perform the re-attachment.
  • In Central Administration, add a content database.
    1. Be sure you have the correct web application selected.
    2. Give the "new" database the same name as the one you specified in SQL Server in step 4 above.  (You're not really "creating" a database at this point because you want to use the existing one that you just re-attached).
    3. Click the "OK" button.

The database should now appear as an available database in Central Administration.  If it's not "Started," be sure to start it.  You should then be able to navigate to any site collection contained in the content database.