Difference between @@servername and SERVERPROPERTY(ServerName)

22 June,2017 by Jack Vamvas

I could not reliably determine the server's network name using @@servername. I executed a SELECT @@servername and the values returned were different to the SERVERPROPRTY(ServerName).

I was under the impression these values are the same , could explain to me the basic difference?

Answer: As a first step , this is the text straight from the MSDN site -

 

Although the @@SERVERNAME function and the SERVERNAME property of SERVERPROPERTY function may return strings with similar formats, the information can be different. The SERVERNAME property automatically reports changes in the network name of the computer.

@@SERVERNAME returns the value from sys.sysservers. Typically you can adjust the value in sys.sysservers – by using the stored procedures

sp_dropserver 'MY_SERVER';
GO
sp_addserver   'MYSERVER1', local; 
GO

 

Read more about using these stored procedures - SQL Server – Change @@servername - sp_dropserver and sp_addserver

You’ll notice if you make a change using these stored procedures and complete a SQL Server restart , there will be a new value for @@SERVERNAME. But SERVERPROPRTY(ServerName) will remain the same.

 

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Difference between @@servername and SERVERPROPERTY(ServerName)


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer