Edit

@@SERVICENAME (Transact-SQL)

Applies to: SQL Server Azure SQL Managed Instance

Returns the name of the registry key under which SQL Server is running.

If the current instance is the default instance, @@SERVICENAME returns MSSQLSERVER. If the current instance is a named instance, @@SERVICENAME returns the instance name.

Transact-SQL syntax conventions

Syntax

@@SERVICENAME

Return types

nvarchar

Remarks

SQL Server runs as a service named MSSQLServer.

Examples

The following example shows using @@SERVICENAME for a default instance.

SELECT @@SERVICENAME AS 'Service Name';

Here's the result set.

Service Name
------------------------------
MSSQLSERVER

The following example shows using @@SERVICENAME for the named instance localhost\SQL2025.

SELECT @@SERVICENAME AS 'Service Name';

Here's the result set.

Service Name
------------------------------
SQL2025