Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance
Returns the name of the local server that is running SQL Server.
Transact-SQL syntax conventions
@@SERVERNAME
nvarchar
SQL Server Setup sets the server name to the computer name during installation. To change the name of the server, use sp_addserver, and then restart SQL Server.
With multiple instances of SQL Server installed, @@SERVERNAME
returns the following local server name information if the local server name didn't change since it was 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> |
Although the @@SERVERNAME
function and the SERVERNAME
property of SERVERPROPERTY function might 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
doesn't report such changes. @@SERVERNAME
reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure.
The following example shows using @@SERVERNAME
.
SELECT @@SERVERNAME AS 'Server Name';
Here's a sample result set.
Server Name
---------------------------------
ACCTG
Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register today