By: Edwin Sarmiento | Updated: 2013-05-14 | Comments (4) | Related: > 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.
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.
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
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.
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
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
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
- Review the following tips
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2013-05-14