Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.92 KB

servername-transact-sql.md

File metadata and controls

75 lines (55 loc) · 2.92 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
@@SERVERNAME (Transact-SQL)
@@SERVERNAME (Transact-SQL)
VanMSFT
vanto
randolphwest
07/08/2024
sql
t-sql
reference
@@SERVERNAME
@@SERVERNAME_TSQL
@@SERVERNAME function
local servers [SQL Server]
TSQL

@@SERVERNAME (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]

Returns the name of the local server that is running [!INCLUDE ssNoVersion].

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

@@SERVERNAME

Return types

nvarchar

Remarks

[!INCLUDE ssNoVersion] Setup sets the server name to the computer name during installation. To change the name of the server, use sp_addserver, and then restart [!INCLUDE ssNoVersion].

With multiple instances of [!INCLUDE ssNoVersion] 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.

Examples

The following example shows using @@SERVERNAME.

SELECT @@SERVERNAME AS 'Server Name';

Here's a sample result set.

Server Name
---------------------------------
ACCTG

Related content