Multiple ways to find the name of SQL Server

This post was written by namwar on October 30, 2007
Posted Under: Uncategorized

SQL Server 2005 provides several ways to find the name of the machine or SQL Server instance where you are currently executing your queries. From SQL Server BOL, I have compiled them as follows (Descriptions are copied from SQL Server Books Online)

–Windows computer name on which the server instance is running.

–For a clustered instance, an instance of SQL Server running on a virtual server on Microsoft Cluster Service, it returns the name of the virtual server.

–NULL = Input is not valid, or an error.

SELECT SERVERPROPERTY(‘MachineName’) AS MachineName

GO

 

–Both the Windows server and instance information associated with a specified instance of SQL Server.

SELECT SERVERPROPERTY(‘ServerName’) AS ServerName

GO

 

—NetBIOS name of the local computer on which the instance of SQL Server is currently running.

—For a clustered instance of SQL Server on a failover cluster, this value changes as the instance of SQL Server fails over to other nodes in the failover cluster.

—On a stand-alone instance of SQL Server, this value remains constant and returns the same value as the MachineName property.

Select SERVERPROPERTY(‘ComputerNamePhysicalNetBIOS’) as PhysicalName

Go

 

—Returns the name of the local server running SQL Server.

SELECT @@SERVERNAME AS ServerNameGlobalVar

GO

Reader Comments

This work very Quik? & I get my server name Thanks a Lot!
but I want to get user name i. e login name for running sql server (odbc)

#1 
Written By pradnya on March 26th, 2011 @ 12:07 pm

Thanks

#2 
Written By Psalm on July 19th, 2011 @ 9:49 am

Add a Comment

required, use real name
required, will not be published
optional, your blog address