Pages

Friday, January 15, 2010

Getting the Server Name in SQL Server using @@SERVERNAME

In this post i would like to give you a simple tip on how to get the Server Name of the SQL server.

In order to get the SQL Server - Server name you need to use Global Variable as shown below.

SELECT @@SERVERNAME AS Server_Name

1 comment:

Nagaraj Venkatesan said...

Hi vijay,

Just wanted to add something to your post. If servername is changed then @@servername still points to the oldname. Updated name can be found by Serverproperty('Servername').

Updated servername will reflect on sql server after one does sp_dropserver and then continue with sp_addserver 'newname','local' and then perform a service restart.

You may be aware of these. Just wanted to add to ur post. :)

Regards,
Raj