Learn more about SQL Server tools



solving sql server problems for millions of dbas and developers since 2006 join MSSQLTips for free SQL Server tips


























































   Got a SQL tip?
            We want to know!

Rename SharePoint Content Database

MSSQLTips author Edwin Sarmiento By:   |   Read Comments (2)   |   Related Tips: > Sharepoint
Problem

I've been tasked to manage the SharePoint 2010 and 2013 database servers after deployment. While looking at the list of databases, I saw several content databases that have GUID values appended to their names. How can I rename the database and remove the GUID value from the name?

Solution

In a previous tip on Renaming the SharePoint Admin Content Database to Follow SQL Server Naming Conventions, you've seen how we can rename the SharePoint Admin Content database and remove the GUID values to follow standard naming conventions. However, there are other SharePoint databases with the GUID values in their names. The most important of these databases are the content databases because they contain the documents, site collections, lists, etc. that end users create.

Here's an example of a SharePoint content database, commonly prefixed with the name WSS_Content before the GUID value.

Here's an example of a SharePoint content database, commonly prefixed with the name WSS_Content before the GUID value

Renaming the SharePoint content databases is similar to renaming the SharePoint Admin Content database. However, instead of just using Windows PowerShell and the SharePoint PowerShell modules to accomplish this task, we will also use T-SQL to rename the database, something that we SQL Server DBAs are familiar with. To accomplish this task, we will be using Windows PowerShell via the SharePoint 2010 Management Shell console. Remember to backup the database prior to performing the tasks below.

Step 1 

On the SharePoint web or application server, click Start, point to All Programs, and then click Microsoft SharePoint 2010 Products. In the list of available options, click SharePoint 2010 Management Shell.

On the SharePoint web or application server, click Start

Step 2

In the SharePoint 2010 Management Shell, type the command below using the Get-SPWebApplication cmdlet. This will retrieve the name of the web application associated with the content database that you want to rename. In my example, I only have one web application but it is associated with four (4) content databases, one of them is the database with a GUID value in the name.

PS C:\> Get-SPWebApplication | Select-Object Url, ContentDatabases | Format-List

SharePoint 2010 Management Shell

Note the value of the web application url in the result - http://sp2010-wfe. We will use this as part of renaming the SharePoint content database.

Step 3

Type the following command to retrieve a list of all the site collections stored in this content database, using the Get-SPContentDatabase cmdlet. We will use the results of this command to verify if the database rename process is successful by accessing the site collections stored in this content database. Be sure to replace the name of the database to the one that you want to rename.

PS C:\> Get-SPContentDatabase | Where-Object {$_.Name -eq "WSS_Content_310d1222490c4303b1c0b3f2ef6954e7"} | Select-Object Sites | Format-List

Be sure to replace the name of the database to the one that you want to rename

Step 4

Type the following command to detach a SharePoint content database from its currently associated web application, using the Dismount-SPContentDatabase cmdlet. We need to pass the name of the content database as a parameter to the cmdlet.

PS C:\> Dismount-SPContentDatabase WSS_Content_310d1222490c4303b1c0b3f2ef6954e7

Type the following command to detach a SharePoint content database

Step 5

Once the content database has been detached from its associated web application, we can now proceed to rename the database from within SQL Server Management Studio. This can be done either using the Object Explorer or T-SQL. I prefer using T-SQL for this purpose simply because I can switch the database to SINGLE_USER mode while renaming it and revert back to MULTI_USER using the ALTER DATABASE command. This prevents other users and/or applications from accessing the database while I rename it.

Connect to the SQL Server instance that contains the SharePoint databases. I will be using the database name WSS_Content4 as an example, thus, removing the GUID value from the name.

USE MASTER;
GO
ALTER DATABASE  [WSS_Content_310d1222490c4303b1c0b3f2ef6954e7]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE [WSS_Content_310d1222490c4303b1c0b3f2ef6954e7]
MODIFY NAME
= WSS_Content4;
GO
ALTER DATABASE WSS_Content4
SET MULTI_USER
GO

Step 6

After renaming the content database, we need to re-attach it back to the SharePoint farm. We will use the Mount-SPContentDatabase SharePoint PowerShell cmdlet to attach the renamed content database back to the farm. We will pass the name of the original web application that references this content database, the one that we got from step #2 above - http://sp2010-wfe.

PS C:\>  Mount-SPContentDatabase WSS_Content4 -WebApplication http://sp2010-wfe


we need to re-attach it back to the SharePoint farm


Verify that the content database rename process is successful by accessing one of the site collections returned from step #3 above. Make sure that the webpage renders properly without issues. Try navigating thru the different links to make sure that everything is working fine.

In this tip, we've renamed an existing GUID-valued SharePoint content database to remove the GUID value. Repeat the steps above until you've renamed all of the content databases in your SharePoint farm.

Next Steps


Last Update: 5/14/2013


About the author
MSSQLTips author Edwin Sarmiento
Edwin Sarmiento works as a SQL Server DBA for The Pythian Group in Ottawa and is a SQL Server MVP.

View all my tips
Related Resources


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Comments and Feedback:
Tuesday, May 28, 2013 - 12:02:08 PM - jefferson Silva Read The Tip

Thanks very much my friend!!!

 

You saved my word (rsrs).


Friday, April 18, 2014 - 2:08:39 PM - marlo Read The Tip

Thanks. You help me a lot of my problems in just 5 mins. Pinoy Power!!



Post a Comment or Question

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email Notify for updates



Comments
Get free SQL tips:

*Enter Code refresh code


 
Sponsor Information







Copyright (c) 2006-2014 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | free t-shirt | user groups | community | events | first timer?
Some names and products listed are the registered trademarks of their respective owners.