Focused on Moving you Forward Faster
Date: June 2, 2015 - June 3, 2018
Author: Brian Alderman
When creating a web application in SharePoint 2013, it communicates with SQL Server to create the supporting content database. Depending on how the Web Apps are created, it sometimes results in the SharePoint database having a not-so-‘friendly’ database name, which may include a ginormous GUID as part of the name. Working with these databases can make it challenging to specify the name of the database within PowerShell or SQL Server, so renaming the database to something more user-friendly is recommended. You may also decide to move the database to a different location on your hard drives without needing to recreate the Web App.
This blog article will guide you through the steps to move or rename these databases.
Steps to Move or Rename SharePoint Web App Content Databases
- Take the database offline and remove it from within SharePoint.
- Backup the Database (Optional, but strongly recommended in case there are problems).
- Detach the database from within SQL Server.
- Rename the database files (.ldf and .mdf) and match the database name to the file names. If moving the database files to a new location, copy the files to the new location instead.
- In SQL Server, attach the moved and/or renamed database back to SQL Server.
- Add the renamed or moved database back to the Web Application.
In SharePoint:
- Navigate to Central Administration > Application Management > Manage Content Databases.
- Select the correct Web Application using the Web Application dropdown box.
- Click the name of the database you want to move or rename.
- Change the Database Status from Ready to Offline.
- Click the checkbox next to Remove content database (This will not delete the DB in SQL).
- Click Ok on the warning popup box.
- Click Ok again.
In SQL Server:
- Locate and right-click on the current database name in SQL Server Management Studio.
- Click Tasks, then Back Up… to open the Back Up Database configuration dialog box.
- Ensure Backup Type is set to Full, and that the database is selected. Note the location of the backup file, then click Ok to complete the backup.
- Right-click the current database name in SQL Server Management Studio and click Properties. Under Files, note the Path of each database file in the details pane.
- Right-click the current database name and click Tasks, then Detach….
- In the Detach Database dialog box, check Drop Connections and click Ok.
Note: The current database name will no longer be available in SQL Server Management Studio.
In Windows Explorer:
- Open Windows Explorer and locate the path of the database files noted earlier.
- Rename the files to reflect the new database name (keeping default file extensions is best practice). If moving files, copy them to the new location.
- Close Windows Explorer and return to SQL Server Management Studio.
In SQL Server (continued):
- In the left pane, right-click Databases and click Attach….
- Click the Add button and locate the directory containing the .mdf file, highlighting it. The .ldf file should also be added.
- Specify the new database name in the Attach As section.
- Under the Current File Path section, click on the new file names and then click Ok.
In SharePoint (final steps):
- Navigate back to Central Administration > Application Management > Manage Content Databases.
- Choose the correct Web Application using the Web Application dropdown box.
- Click Add a Content Database.
- Enter the new database name in the Database Name box and click Ok.
Congratulations, you have now successfully renamed and/or moved the SharePoint content database and its associated files.
Oh, don’t forget to delete the backup created in earlier steps and say goodbye to those GUIDs!