Saturday , June 10 2023

How To Change SQL Instance/Server Name ANS @@SERVERNAME Function

Sometimes the name of the server changes and the SQL Server instance name must change accordingly.

For example, suppose your server name is a test and you have an instance named testinstance on your test server.

You can normally connect to Instance as “test\testinstance”.

Suppose that the name of the test server is changed to “prod”.

If you want to query the name of instance with the command Select @@SERVERNAME, you will see that your instance name is still “test\testinstance”.

We can fix this with the code below.

If you are using SQL Server 2012 or newer version, you will receive the below error when you execute the above script. Because sp_addserver is no longer supported in SQL Server 2012 and newer versions.

Msg 15663, Level 16, State 1, Procedure sp_MSaddserver_internal, Line 60 [Batch Start Line 0]

Feature “sp_addserver” is no longer supported. Replace remote servers by using linked servers.

To solve the error, use sp_addlinkedserver instead of sp_addserver.


About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *