In SQL Server, the @@SERVICENAME
configuration function returns the name of the registry key under which SQL Server is running.
No argument is required. You can simply use it in a SELECT
statement to return the registry key’s name.
Note that SQL Server runs as a service named MSSQLServer. The @@SERVICENAME
function returns MSSQLSERVER if the current instance is the default instance. It returns the instance name if the current instance is a named instance.
Example
Here’s an example to demonstrate.
SELECT @@SERVICENAME AS [Service Name];
Result:
+----------------+ | Service Name | |----------------| | MSSQLSERVER | +----------------+
In my case, I ran this statement on the default instance of SQL Server, and so MSSQLSERVER was returned.
The return value is nvarchar.