@@SERVERNAME

Transact-SQL Reference

Transact-SQL Reference

@@SERVERNAME

Returns the name of the local server running Microsoft® SQL Server™.

Syntax

@@SERVERNAME

Return Types

nvarchar

Remarks

SQL Server Setup sets the server name to the computer name during installation. Change @@SERVERNAME by using sp_addserver and then restarting SQL Server. This method, however,  is not usually required.

With multiple instances of SQL Server installed, @@SERVERNAME returns the following local server name information if the local server name has not been changed since setup.

Instance Server information
Default instance 'servername'
Named instance 'servername\instancename'
Virtual server - default instance 'virtualservername'
Virtual server - named instance 'virtualservername\instancename'

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.

In contrast, @@SERVERNAME does not report such changes. @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure.

Examples
SELECT @@SERVERNAME

See Also

Configuration Functions

SERVERPROPERTY

sp_addserver