9.2 Modifying the computer name
9.2.1 Display computer Name
When you install SQL Server, the Setup program sets the name of the local computer to computer name and saves it as a global variable @ @SERVERNAME. If you modify the name of the local computer after the installation is complete, the @ @SERVERNAME does not change.
The SERVERPROPERTY system function returns the network name of the current local computer.
The following script can display both results at the same time.
SELECT @ @SERVERNAME as Installedname, serverproperty (' SERVERNAME ') as NetworkName |
In the previous example, if the values of the two columns returned are not the same, you can determine that the computer has modified the computer name after installation. The first column returns the computer name when SQL Server was installed, and the second column returns the current computer name.
9.2.2 Modifying the computer name
When you find that two names do not match, you can refer to the Microsoft Official website example to modify.
EXEC sp_dropserver ' Current_server_name '; GO EXEC sp_addserver ' new_server_name ', ' local '; GO |
After you modify the computer name, you need to restart Windows to take effect.
The complete script is as follows:
IF @ @SERVERNAME <> serverproperty (' SERVERNAME ') BEGIN EXEC sp_dropserver @server = @ @SERVERNAME DECLARE @new_server_name SYSNAME SELECT @new_server_name = CAST (serverproperty (' servername ') as SYSNAME) EXEC sp_addserver @server = @new_server_name, @local = ' local ' END |
This article from "SQLServer2014 series" blog, declined reprint!
9.2 Modifying the computer name