Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Configuration FunctionsRSS Feeds

@@SERVERNAME - SERVERNAME Function

Posted By: Sarita Patel     Category: SQL Server     Views: 1896

This article explains about @@SERVERNAME function in sql server with examples.

@@SERVERNAME function is used to get name of the local server running sql server.


Syntax of @@SERVERNAME Function :

@@SERVERNAME

Return type of @@SERVERNAME function is nvarchar.



Examples of @@SERVERNAME Function :

Example 1 : Use of @@SERVERNAME function in select clause

SELECT @@SERVERNAME

Output
ABC\SQLEXPRESS

Above example returns local server running i.e ABC\SQLEXPRESS.

Note that sql server setup sets the server name to the computer name during installation. Change @@SERVERNAME by using sp_addserver and then restarting 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'

Virtual server - default instance

'virtualservername'

Virtual server - named instance

'virtualservername\instancename'


@@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.

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


Didn't find what you were looking for? Find more on @@SERVERNAME - SERVERNAME Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of @@SERVERNAME - SERVERNAME Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!