[Company Logo Image] 

Home Up Contents Coffee Break Credits Glossary Links Search

 
Determining Server Name using T-SQL

 

 

Home
Analysis Services
Azure
CLR Integration
High Availability
Open Source
Security
SQL Server 2008
SQL Server 2012
SQL Server 2014
SQL Server 2016
SQL Server 2017
SQL Server 2019
Tips
Troubleshooting
Tuning

Determining Server Name using T-SQL


Applies to: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Microsoft SQL Server 2008.


The following instructions are supposed to return the same results,  but sometimes the results can be different. The reason is that SERVERPROPERTY automatically reports changes in the network name of the computer, while @@SERVERNAME don't.
 

SELECT CONVERT(sysname, SERVERPROPERTY(N'servername'))

GO

SELECT @@SERVERNAME

 

When they are run on the default instance they return just the server name, but when run over a named instance they return the server name in the following format: servername/instancename.

 

References.

@@SERVERNAME(Transact-SQL)
SQL Server 2005 Books Online (October 2007)


 

 

.Send mail to webmaster@sqlcoffee.com with questions or comments about this web site.