El Padrino
El Padrino

Reputation: 1171

How to determine the Server Name of a SQL Server with a T-SQL statement?

I want to know if there is a T-SQL statement that returns the Server name of a SQL Server.

Upvotes: 3

Views: 7529

Answers (3)

Aaron Bertrand
Aaron Bertrand

Reputation: 280252

This will give the actual physical machine name (e.g. in case of a cluster) as well as the server\instance name:

SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS'), @@SERVERNAME;

Upvotes: 18

sealz
sealz

Reputation: 5408

SELECT @@servername

MSDN @@servername

Upvotes: 1

AdaTheDev
AdaTheDev

Reputation: 147224

One way is as follows:

SELECT @@SERVERNAME

Another way:

SELECT SERVERPROPERTY('ServerName')

Upvotes: 10

Related Questions