SqlServer更改机器名后如何修改数据库的机
发布网友
发布时间:2022-04-14 19:52
我来回答
共1个回答
热心网友
时间:2022-04-14 21:22
在安装好后服务器,并安装SQL Server软件后,如果需要修改主机名,除了修改注册表里面的东西外,还需要通过如下方式修改SQL Server认到的主机名
sp_dropserver 'PCName1'
sp_addserver 'PCName2','local'
本地的主机名也可以通过select * from sys.servers 来查看。
更详细的信息
-- Run on SQL 2000 after server name change.
-- To correct the sysservers system table. Note the following excerpt from online help about remote users and logins:
-- If the computer has any remote logins, for example, if it is a
-- replication Publisher or Distributor, sp_dropserver may generate
-- an error similar to this:
-- Server: Msg 15190, Level 16, State 1, Procere sp_dropserver, Line 44
-- There are still remote logins for the server 'SERVER1'.
-- To resolve the error, you may need to drop remote logins for this server.
-- If replication is installed, disable replication on the server before
-- running the sp_dropserver stored procere.
-- Side note:
--
--SQL Books Online is slightly incorrect with regard to sp_addserver when renaming a server. The correct syntax is
-- exec sp_addserver '<NEWSERVERNAME>', 'local'
--
-- If you do it the way it is specified in books online, the server is added with a new server id which is an identity field.
-- If you try to replicate from (and possibly to) this server, replication setup will fail because it is looking for a server
-- with an ID of 0 which won't be there. For some reason it uses this to determine something about the local computer
-- and bombs.
exec sp_dropserver <old servername>
go
exec sp_addserver <new servername>', 'local'
go
-- To correct orginating server on JOBS: If this isn't done, the jobs on
-- the server can't be edited, SQL thinks they came from another server
update msdb.dbo.sysjobs
set originating_server = '<new servername>'
where originating_server = '<old servername>'
go