Steps to change the server name for a SQL Server machine
As you may know, the internal SQL Server name is based on the physical server name, but changing the physical server name does not update the metadata within SQL Server.
When connecting to SQL Server, we use the physical server name for the default instance and physical server name\INSTANCE Name for a named instance. If you change the physical server name, there is no need to re-install SQL Server to reset the physical server name. You can follow the below steps to update the SQL Server system metadata which stores the physical server name in sys.servers.
The below solution works for default and named SQL instances on a standalone machine (non-clustered). Also, you need to follow the steps for each SQL Server instance on the machine.
Pre Update Steps
Check for Remote Logins
- If remote logins exist you have to drop them first, if you do not drop the remote logins you will get the below error when executing the sp_dropserver stored procedure.
- You can run this query to get a list of remote logins that exist on the server.
Check for Replication
- SQL Server does not support renaming computers that are involved in replication. If the SQL Server is involved in replication you have to remove it first. If you do not remove replication, you will get the below error when updating SQL Server System metadata.
- You can run this query to see if replication is in place. If so, you could script out the settings first so you can recreate afterwards and then remove replication.
Check for Reporting Services
- If SQL Server Reporting Service is installed and configured, you have to first stop the Reporting Services service.
Check for Database Mirroring
- If database mirroring is enabled you have to remove mirroring and then re-establish mirroring once you have made the system metadata update.
Steps to rename SQL Server
- Execute the below commands for each instance on the machine.
- Restart the SQL Server services.
- Execute the below query in each instance to verify the updated system metadata.
Post Update Steps
- Add the remote logins using the sp_addremotelogin command.
- Reconfigure Replication if this was setup.
- Reconfigure Database Mirroring if this was setup.
- Reconfigure Reporting Services if this was setup and connect to the new server name as shown below.
- If you also changed the Report Server computer name, you will have to edit the RSReportServer.config file and update theURLRoot setting. Do to this, open the RSWebApplication.config file and modify the ReportServerUrl setting to reflect the new server name.
- Change application connection strings pointing to the server
- Change linked servers pointing to the server