Rename SharePoint Content Database

By:   |   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.

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


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Edwin Sarmiento Edwin M Sarmiento is a Microsoft SQL Server MVP and Microsoft Certified Master from Ottawa, Canada specializing in high availability, disaster recovery and system infrastructures.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Wednesday, June 14, 2023 - 11:37:21 AM - Pitsi Back To Top (91288)
I get this error when i try to very if the site is opening and in Central Admin i dont see the site collection under that web application
HTTP/1.1 200 OK
Server: Microsoft-IIS/10.0
Date: Wed, 14 Jun 2023 15:33:18 GMT
Connection: close

Monday, November 7, 2016 - 4:42:27 AM - Bactius Back To Top (43710)

Thank you!

 


Friday, April 18, 2014 - 2:08:39 PM - marlo Back To Top (30104)

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


Tuesday, May 28, 2013 - 12:02:08 PM - jefferson Silva Back To Top (25168)

Thanks very much my friend!!!

 

You saved my word (rsrs).















get free sql tips
agree to terms