So I’ve been toying with SharePoint 2013 in my lab at home, doing the install and configuration at the moment, setting up my first Site after the initial configuration but noticed that I made a typo in the Database name. So how do I go about fixing or renaming that database in SharePoint and in SQL Server.
First thing first is we need to know the name of the Content database, in my case it is easy, because we only have one and I can easily see the spelling mistake I made. But if you need to work out the name of the Database, you can look in Application Management > Manage Content Databases and click on the Site Collection you are after; alternatively you can use SharePoint’s management shell and issue the following two cmdlet’s;
Get-SPWebApplication | Select-Object Url, ContentDatabases | Format-List
What sites are using this content database;
Get-SPContentDatabase | Where-Object {$_.Name -eq "SharePint_ContosoContent"} | Select-Object Sites | Format-List
So now we know the name of our content database, we need dismount it before we can rename it in SQL Server. To dismount use the following cmdlet;
Dismount-SPContentDatabase SharePint_ContosoContent
Now the database is ready to rename. Open up SQL Management Studio and connect to your Database Server hosting SharePoint. Now usually when you go to rename a database you will get an error message stating that the database is in use. To get around that we turn our database into Single User mode, rename it and then set it back to multi user mode with the following SQL snippet.
USER Master
-- Set to Single User to prevent unable to lock out
ALTER DATABASE SharePint_ContosoContentDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
-- Rename Database
ALTER DATABASE SharePint_ContosoContentDB MODIFY NAME = [SharePoint_ContosoContentDB]
-- Set back to multi user for production use
ALTER DATABASE SharePoint_ContosoContentDB SET MULTI_USER
Now once we have renamed the database on our SQL Server, it is time to mount it back onto SharePoint, we do that by issuing the following PowerShell on our SharePoint server
Mount-SPContentDatabase SharePoint_ContosoContentDB -WebApplication http://intranet.contoso.com/
And there you have it, renaming a SharePoint content database if you make a typo like me.
Share this post with others: