In SQL Server, the @@SERVERNAME configuration function returns the name of the local server that is running SQL Server.
No argument is required. You can simply use it in a SELECT statement to return the server name.
Example
Here’s an example to demonstrate.
SELECT @@SERVERNAME AS [Server Name];
Result:
+---------------+ | Server Name | |---------------| | sqlserver007 | +---------------+
The return value is nvarchar.
Microsoft advises that, 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 set up.
| Instance | Server information |
|---|---|
| Default instance | ‘servername‘ |
| Named instance | ‘servername\instancename‘ |
| failover cluster instance – default instance | ‘network_name_for_fci_in_wsfc‘ |
| failover cluster instance – named instance | ‘network_name_for_fci_in_wsfc\instancename‘ |
Also note that @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure, but it doesn’t report changes in the network name of the computer.