9.2 Modifying the computer name

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.