重新命名主控 SQL Server 獨立式執行個體的電腦Rename a Computer that Hosts a Stand-Alone Instance of SQL Server

本主題的適用對象: 是SQL Server沒有Azure SQL Database沒有Azure SQL 資料倉儲沒有Parallel Data WarehouseTHIS TOPIC APPLIES TO: yesSQL ServernoAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse 當您變更了執行 SQL ServerSQL Server 的電腦名稱之後,便會在 SQL ServerSQL Server 啟動期間辨識這個新名稱。 When you change the name of the computer that is running SQL ServerSQL Server, the new name is recognized during SQL ServerSQL Server startup. 您不必重新執行安裝程式,即可重設電腦名稱。You do not have to run Setup again to reset the computer name. 請改用下列步驟來更新儲存在 sys.servers 中而且由系統函式 @@SERVERNAME 所報告的系統中繼資料。Instead, use the following steps to update system metadata that is stored in sys.servers and reported by the system function @@SERVERNAME. 您可以更新系統中繼資料,以便反映使用 @@SERVERNAME 或從 sys.servers 中查詢伺服器名稱之遠端連接和應用程式的電腦名稱變更。Update system metadata to reflect computer name changes for remote connections and applications that use @@SERVERNAME, or that query the server name from sys.servers.

您不能使用下列步驟重新命名 SQL ServerSQL Server的執行個體。The following steps cannot be used to rename an instance of SQL ServerSQL Server. 這些步驟只能用來重新命名執行個體名稱中與電腦名稱相對應的部分。They can be used only to rename the part of the instance name that corresponds to the computer name. 例如,您可以將主控 SQL ServerSQL Server 執行個體 (名為 Instance1) 的電腦名稱 MB1 改成其他名稱,例如 MB2。For example, you can change a computer named MB1 that hosts an instance of SQL ServerSQL Server named Instance1 to another name, such as MB2. 不過,該名稱中的執行個體部分 Instance1 將保持不變。However, the instance part of the name, Instance1, will remain unchanged. 在這個範例中, \\ComputerName\InstanceName 會從 \\MB1\Instance1 變更為 \\MB2\Instance1。In this example, the \\ComputerName\InstanceName would be changed from \\MB1\Instance1 to \\MB2\Instance1.

開始之前Before you begin

在開始執行重新命名程序之前,請先檢閱下列資訊:Before you begin the renaming process, review the following information:

  • SQL ServerSQL Server 執行個體是 SQL ServerSQL Server 容錯移轉叢集的一部分時,此電腦的重新命名程序與主控獨立執行個體的電腦程序不同。When an instance of SQL ServerSQL Server is part of a SQL ServerSQL Server failover cluster, the computer renaming process differs from a computer that hosts a stand-alone instance.

  • SQL ServerSQL Server 不支援在複寫時重新命名電腦,但在複寫時使用記錄傳送的情況例外。 does not support renaming computers that are involved in replication, except when you use log shipping with replication. 如果主要電腦已永久遺失,可以重新命名記錄傳送的次要電腦。The secondary computer in log shipping can be renamed if the primary computer is permanently lost. 如需詳細資訊,請參閱記錄傳送和複寫 (SQL Server)For more information, see Log Shipping and Replication (SQL Server).

  • 當您要重新命名設定為使用 Reporting ServicesReporting Services 的電腦時, Reporting ServicesReporting Services 在電腦名稱變更之後可能無法使用。When you rename a computer that is configured to use Reporting ServicesReporting Services, Reporting ServicesReporting Services might not be available after the computer name change. 如需詳細資訊,請參閱 重新命名報表伺服器電腦For more information, see Rename a Report Server Computer.

  • 當您要重新命名已設定為使用資料庫鏡像的電腦時,您必須在重新命名作業之前關閉資料庫鏡像。When you rename a computer that is configured to use database mirroring, you must turn off database mirroring before the renaming operation. 然後使用新的電腦名稱,重新建立資料庫鏡像。Then, re-establish database mirroring with the new computer name. 資料庫鏡像的中繼資料並不會自動更新來反映新的電腦名稱。Metadata for database mirroring will not be updated automatically to reflect the new computer name. 請使用下列步驟來更新系統中繼資料。Use the following steps to update system metadata.

  • 透過以硬式編碼方式參考電腦名稱的 Windows 群組來連接到 SQL ServerSQL Server 的使用者,可能無法連接到 SQL ServerSQL ServerUsers who connect to SQL ServerSQL Server through a Windows group that uses a hard-coded reference to the computer name might not be able to connect to SQL ServerSQL Server. 如果 Windows 群組指定舊的電腦名稱,則重新命名之後可能會發生這個狀況。This can occur after the rename if the Windows group specifies the old computer name. 為了確保這種 Windows 群組在重新命名作業之後仍能連接 SQL ServerSQL Server ,請更新 Windows 群組,以指定新的電腦名稱。To ensure that such Windows groups have SQL ServerSQL Server connectivity following the renaming operation, update the Windows group to specify the new computer name.

    重新啟動 SQL ServerSQL Server 之後,您可以使用新的電腦名稱連接到 SQL ServerSQL ServerYou can connect to SQL ServerSQL Server by using the new computer name after you have restarted SQL ServerSQL Server. 為了確定 @@SERVERNAME 傳回已更新的本機伺服器執行個體名稱,您應該手動執行下列適用於您狀況的程序。To ensure that @@SERVERNAME returns the updated name of the local server instance, you should manually run the following procedure that applies to your scenario. 您所使用的程序需視正在更新的電腦是主控 SQL ServerSQL Server預設執行個體還是具名執行個體而定。The procedure you use depends on whether you are updating a computer that hosts a default or named instance of SQL ServerSQL Server.

重新命名裝載 SQL ServerSQL Server 獨立執行個體的電腦Rename a computer that hosts a stand-alone instance of SQL ServerSQL Server

  • 若為主控 SQL ServerSQL Server預設執行個體的重新命名電腦,請執行下列程序:For a renamed computer that hosts a default instance of SQL ServerSQL Server, run the following procedures:

    sp_dropserver <old_name>;  
    GO  
    sp_addserver <new_name>, local;  
    GO  
    

    重新啟動 SQL ServerSQL Server的執行個體。Restart the instance of SQL ServerSQL Server.

  • 若為主控 SQL ServerSQL Server具名執行個體的重新命名電腦,請執行下列程序:For a renamed computer that hosts a named instance of SQL ServerSQL Server, run the following procedures:

    sp_dropserver <old_name\instancename>;  
    GO  
    sp_addserver <new_name\instancename>, local;  
    GO  
    

    重新啟動 SQL ServerSQL Server的執行個體。Restart the instance of SQL ServerSQL Server.

在重新命名作業之後After the Renaming Operation

在重新命名電腦之後,使用舊電腦名稱的任何連接都必須使用新名稱來連接。After a computer has been renamed, any connections that used the old computer name must connect by using the new name.

確認重新命名作業Verify renaming operation

  • 從 @@SERVERNAME 或 sys.servers 中選取資訊。Select information from either @@SERVERNAME or sys.servers. @@SERVERNAME 函式會傳回新名稱,而且 sys.servers 資料表會顯示新名稱。The @@SERVERNAME function will return the new name, and the sys.servers table will show the new name. 下列範例示範如何使用 @@SERVERNAME。The following example shows the use of @@SERVERNAME.

    SELECT @@SERVERNAME AS 'Server Name';  
    

其他考量Additional considerations

遠端登入 - 如果電腦上已有遠端登入,則執行 sp_dropserver 可能會產生類似下面的錯誤:Remote Logins - If the computer has any remote logins, running sp_dropserver might generate an error similar to the following:

Server: Msg 15190, Level 16, State 1, Procedure sp_dropserver, Line 44 There are still remote logins for the server 'SERVER1'.

若要解決錯誤,您必須卸除這部伺服器的遠端登入。To resolve the error, you must drop remote logins for this server.

卸除遠端登入Drop remote logins

  • 如果是預設執行個體,請執行下列程序:For a default instance, run the following procedure:

    sp_dropremotelogin old_name;  
    GO  
    
  • 如果是具名執行個體,請執行下列程序:For a named instance, run the following procedure:

    sp_dropremotelogin old_name\instancename;  
    GO  
    

    連結的伺服器組態 - 連結的伺服器組態將會受到電腦重新命名作業影響。Linked Server Configurations - Linked server configurations will be affected by the computer renaming operation. 您可以使用 sp_addlinkedserversp_setnetname 更新電腦名稱參考。Use sp_addlinkedserver or sp_setnetname to update computer name references. 如需詳細資訊,請參閱 sp_addlinkedserver (Transact-SQL)sp_setnetname (Transact-SQL)For more information, see the sp_addlinkedserver (Transact-SQL) or sp_setnetname (Transact-SQL).

    用戶端別名名稱 - 使用具名管道的用戶端別名將會受到電腦重新命名作業影響。Client Alias Names - Client aliases that use named pipes will be affected by the computer renaming operation. 例如,如果您建立了指向 SRVR1 的別名 "PROD_SRVR" 並且使用具名管道通訊協定,此管道名稱將會類似這樣: \\SRVR1\pipe\sql\queryFor example, if an alias "PROD_SRVR" was created to point to SRVR1 and uses the named pipes protocol, the pipe name will look like \\SRVR1\pipe\sql\query. 重新命名電腦之後,具名管道的路徑將不再有效。After the computer is renamed, the path of the named pipe will no longer be valid and. 如需具名管道的詳細資訊,請參閱 使用具名管道建立有效的連接字串For more information about named pipes, see the Creating a Valid Connection String Using Named Pipes.

另請參閱See also

安裝 SQL ServerInstall SQL Server