T-SQL Tutorial

How to get SQL Server local server name


To get SQL Server local server name uses the function named @@SERVERNAME. SQL Server Setup sets the server name to the computer name during installation. To change the name of the server, use sp_addserver, and then restart SQL Server.

Syntax

SELECT @@SERVERNAME;

Example

SELECT @@SERVERNAME AS 'Local server name';

Local server name
MSSQLSERVER_TEST

See also: @@SERVERNAME