SQL SERVER – How to Get List of SQL Server Instances Installed on a Machine Via T-SQL?

A registry query lists SQL Server Instances recorded on the Windows host. A customer wanted a T-SQL-only method.

A fitted key inventory is inspected within one room while distant doors remain outside its scope.

SELECT SERVERPROPERTY('MachineName') AS MachineName,
       SERVERPROPERTY('ServerName') AS ServerName,
       SERVERPROPERTY('InstanceName') AS InstanceName;
-- Historical Windows registry inspection, not a portable supported DMV:
DECLARE @Instances TABLE (Value nvarchar(100), InstanceNames nvarchar(100), Data nvarchar(100));
INSERT @Instances
EXEC master.dbo.xp_regread
    @rootkey = N'HKEY_LOCAL_MACHINE',
    @key = N'SOFTWARE\Microsoft\Microsoft SQL Server',
    @value_name = N'InstalledInstances';
SELECT InstanceNames FROM @Instances;

Zol’taan’s comment reminded me to share this technique. It reads the SQL Server host’s registry, rather than the SSMS workstation. Registry view, installation state and permissions affect the result. xp_regread isn’t a documented portable catalog contract.

Verify registry results against installed services or a Setup discovery report. SERVERPROPERTY answers a separate question about the connected instance. InstanceName is NULL for a default instance. Neither query discovers every reachable SQL Server.

The earlier instance-name resources provide related approaches. Don’t grant broad privileges solely to make a registry helper work. Use an approved discovery method for the actual inventory scope.

Related reading

A local instance inventory is not network discovery, it is information about the connected host.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Scripts, SQL Server
Previous Post
Drop Multiple Tables with One DROP TABLE Statement
Next Post
SQL SERVER – Reporting Services Not Starting After Maintenance Window

Related Posts

3 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.