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
–Both the Windows server and instance information associated with a specified instance of SQL Server.
SELECT SERVERPROPERTY(‘ServerName’) AS ServerName
—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
—Returns the name of the local server running SQL Server.
SELECT @@SERVERNAME AS ServerNameGlobalVar