Hey guys,
Good morning!
In this post, I will demonstrate how to rename the server/instance in the database when the machine name is changed in the operating system, which is relatively common to happen in everyday life.
When this happens, the machine name in the operating system becomes different from the machine name in the database, and you can notice this when using functions like @@SERVERNAME, for example.
One way to always retrieve updated information is by using the SERVERPROPERTY(‘Servername’) function, which retrieves the information directly from the operating system. When it returns a result different from @@SERVERNAME, this means that the name registered in SQL Server is different from the real name of the machine.
To fix this type of problem, simply run the commands below:
-- Para a instância padrão (MSSQLServer)
EXEC sp_dropserver 'nome_antigo'
GO
EXEC sp_addserver 'nome_atual', local
GO
-- Para instâncias nomeadas (ex: servidor\sql2016)
EXEC sp_dropserver 'servidor_antigo\instancia'
GO
EXEC sp_addserver 'servidor_novo\instancia', local
GO
After making these changes, restart the SQL Server service and the @@SERVERNAME function will return the correct server name.
For more information, see the official Microsoft documentation through this link.
A hug and see you in the next post.
Comentários (0)
Carregando comentários…