SQL Server - How to rename server / instance in database when machine name is changed in OS

Views: 4.869
Reading Time: <1 minute

Hello people,
Good Morning!

In this post, I will demonstrate how to rename the server / instance in the database when the hostname changes in the operating system, which is relatively common in everyday life.

When this happens, the hostname in the operating system is different from the hostname in the database, and you may notice this when using functions such as @@ SERVERNAME, for example.

One way to always retrieve updated information is by using the SERVERPROPERTY ('Servername') function, which retrieves the information directly from the operating system. When it gives a different result than @@ SERVERNAME, it means that the name registered in SQL Server is different from the actual name of the machine.

To fix this kind of problem, simply run the following commands:

After making these changes, restart the SQL Server service and the @@ SERVERNAME function will return the correct server name.

For more information, see the official Microsoft documentation. through this link.

Regards and see you next post.