新安装的sqlserver 2008 R2,并还原数据库后,修改了服务器的主机名称,导致sqlserver的实例名称有变化.

一下是查询方式语句

use master
go
select @@SERVERNAME
select SERVERPROPERTY('servername')

 下面是修改语句

use master
go
if SERVERPROPERTY('servername') <> @@SERVERNAME
begin
declare @server sysname
set @server = @@SERVERNAME
exec sp_dropserver @server=@server
set @server= CAST(SERVERPROPERTY('servername') as sysname)
exec sp_addserver @server = @server,@local='LOCAL'
end

 修改后,重启sqlserver ,再次验证实例名称.