[SQL Server] Server 名稱變更後如何更改SQL Server資料庫中的hostname

摘要:[SQL Server] Server 名稱變更後如何更改SQL Server資料庫中的hostname

SELECT @@SERVERNAME As [@@SERVERNAME],
  CAST(SERVERPROPERTY('MACHINENAME') AS VARCHAR(128)) + COALESCE('\' + CAST(SERVERPROPERTY('INSTANCENAME') AS VARCHAR(128)), '') As RealInstanceName;


-- Script to correct the @@SERVERNAME
DECLARE @InternalInstanceName sysname;
DECLARE @MachineInstanceName sysname;

SELECT @InternalInstanceName = @@SERVERNAME,
  @MachineInstanceName = CAST(SERVERPROPERTY('MACHINENAME') AS VARCHAR(128))
    + COALESCE('\' + CAST(SERVERPROPERTY('INSTANCENAME') AS VARCHAR(128)), '');
IF @InternalInstanceName <> @MachineInstanceName
BEGIN

 -- Rename the instance
 EXEC sp_dropserver @InternalInstanceName;
 EXEC sp_addserver @MachineInstanceName, 'LOCAL';
END
 

0推薦此文章
 





 

 

 

 

 

請大家永躍參與Facebook MSBI 粉思團:http://www.facebook.com/#!/group.php?gid=303757165010