Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 @@SERVERNAME (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
@@SERVERNAME (Transact-SQL)

Returns the name of the local server that is running SQL Server.

Topic link icon 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 has not been changed since setup.

Instance Server information

Default instance

'servername'

Named instance

'servername\instancename'

failover clustered instance - default instance

'virtualservername'

failover clustered instance - 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.

The following example shows using @@SERVERNAME.

SELECT @@SERVERNAME AS 'Server Name'

Here is a sample result set.

Server Name
---------------------------------
ACCTG
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker