How to get SQL Server instance name

To get SQL Server instance name or service name uses the function named @@SERVICENAME. SQL Server runs as a service named MSSQLServer.

Syntax

SELECT @@SERVICENAME;

Example

SELECT @@SERVICENAME AS 'SQL Server Instance Name';

SQL Server Instance Name
MSSQLSERVER

See also: @@SERVICENAME