Pages

Wednesday, August 22, 2012

@@Servername is returning NULL in SQL Server

Global Variable @@servername is returning NULL or Change the SQL Server Name


Global Variable @@servername will return the name of LOCAL SERVER name created at time of installation.

UID of the servername will be "0".

Sometimes after installation of some hotfixes or patches we have observed that @@servername variable is returning NULL.

We can change that by using the procedures below mentioned.

sp_addserver 'servername'

Above procedure when execute we will create a new server in the list of SYS.SERVERS with UID > 0

Even after the execution of above statement will not reflect the server name in @@servername untill the SQL Server RESTART happens.

To enforce the new name for SQL Server, RESTART is mandatory.

Use the below syntax for the servername to reflect with UID as "0".

Select @@servername
Go
sp_dropserver 'servername'
Go
sp_addserver 'Newservername',local
Go
select @@servername
Go
select * from sys.servers
Go

Hope the above information helps

Thanks