I'm trying to determine what instances of sql server/sql express I have installed (either manually or programmatically) but all of the examples are telling me to run a SQL query to determine this which assumes I'm already connected to a particular instance.
-
2Here is a link how to identify with sqlcmd http://msdn.microsoft.com/en-us/library/ms165662%28v=sql.90%29.aspx – Jun 12 '13 at 08:19
-
How to Find Your SQL Server Instances (Server Name) and Versions https://www.youtube.com/watch?v=DLrxFXXeLFk – mloskot Nov 04 '14 at 14:23
-
can you tell me the SQL queries you are speaking of? – LearnByReading Feb 12 '16 at 14:49
-
1@LearnByReading See Mohammed Ifteqar Ahmed's answer below. – Luke Feb 22 '16 at 13:10
-
2You can interrogate the registry: http://pmichaels.net/2016/02/12/list-the-installed-instances-of-sql-server/ – Paul Michaels Feb 28 '16 at 15:47
-
The other solutions did not worked for me Cause I am sure I have few named instances , these solutions just shows default instance. But Visual Studios SQL Server Object Explorer Window lists all local named and unnamed instances of sql server. Just hit add sql server image button and under local arrow all instances are listed. Maybe this helps – yigitt Dec 29 '16 at 22:59
21 Answers
At a command line:
SQLCMD -L
or
OSQL -L
(Note: must be a capital L)
This will list all the sql servers installed on your network. There are configuration options you can set to prevent a SQL Server from showing in the list. To do this...
At command line:
svrnetcn
In the enabled protocols list, select 'TCP/IP', then click properties. There is a check box for 'Hide server'.

- 98,240
- 88
- 296
- 433

- 24,112
- 4
- 51
- 59
-
3I like the command-line options, but I got mixed results when I tried them on my (non-networked) developer box; basically "sqlcmd -L" was the only one that worked, and only if the SQL Server Browser Service was running. Is that to be expected? – Matt Sep 27 '08 at 09:32
-
I LOVE it when it is SIMPLE and STRAIGHT. I was struggling to find the right server name to enter for an Amazon Web Service SQL Server instance. ThanX – Mehdi LAMRANI May 06 '11 at 11:40
-
1Nice commands but for some reason it detected the SQLExpress instance on a network computed but failed to detect the SQLExpress instance on my local machine. – sparebytes May 05 '15 at 18:41
-
1@sparebytes: reason here: http://dba.stackexchange.com/questions/18499/why-does-sqlcmd-lc-not-show-the-local-instance – DonBecker Jan 22 '16 at 15:05
-
2
-
What is the cmd code for Mac? I tried the same code in Mac terminal but not working... – Md Aslam Jan 24 '20 at 17:18
-
I don't know anything about Mac. Would this help: https://cloudblogs.microsoft.com/sqlserver/2017/04/03/sql-server-command-line-tools-for-mac-preview-now-available/ – George Mastros Jan 26 '20 at 18:58
-
I'm trying to do this from a fresh docker container but am getting an SSPI context error. SQLCMD works fine in other ways but this doesn't. – Chris Feb 09 '22 at 17:42
You could query this registry value to get the SQL version directly:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\CurrentVersion
Alternatively you can query your instance name and then use sqlcmd with your instance name that you would like:
To see your instance name:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names
Then execute this:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
If you are using C++ you can use this code to get the registry information.

- 1
- 1

- 339,232
- 124
- 596
- 636
-
('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition') shows only server, only running one but not instances or installed but stopped servers – Gennady Vanin Геннадий Ванин Oct 13 '10 at 02:45
-
Thanks, the query worked for me. I had a machine and wanted to know default instance and SQL Express instance which was 2008 and which 2008 R2. I connected to each instance and ran the query and it got me a version number. Googling the numbers then was easy. – Meligy Dec 27 '10 at 03:15
-
3Note, it seems like the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\
\Tools\ClientSetup\CurrentVersion" and "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names" shows up in the 32bit portion of the registry, while the actual path to the instance: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\ – NGaida Oct 11 '13 at 16:45" shows up in the 64bit Hive. -
The registry is the source definition of installed software. Your solution allows me to go directly to the source, rather than using a CLI tool, which ultimately uses registry values, or MMC snap-in which also uses the registry. Perfect – barrypicker Oct 18 '17 at 15:55
All of the instances installed should show up in the Services Snap-In in the Microsoft Management Console. To get the instance names, go to Start | Run | type Services.msc and look for all entries with "Sql Server (Instance Name)".

- 1,254
- 1
- 9
- 18
-
21Equivalent PowerShell command: `Get-Service | ?{ $_.Name -like "MSSQL*" }` – orad Feb 11 '14 at 04:38
-
2My computer shows MSSQL$SQLEXPRESS is running with display name SQL Server (SQLEXPRESS).... but how do i enter this in a server name? Test connection shows errors like ... a network related or instance specific error occured when trying to connect to sql server – webzy Feb 06 '16 at 09:29
-- T-SQL Query to find list of Instances Installed on a machine
DECLARE @GetInstances TABLE
( Value nvarchar(100),
InstanceNames nvarchar(100),
Data nvarchar(100))
Insert into @GetInstances
EXECUTE xp_regread
@rootkey = 'HKEY_LOCAL_MACHINE',
@key = 'SOFTWARE\Microsoft\Microsoft SQL Server',
@value_name = 'InstalledInstances'
Select InstanceNames from @GetInstances

- 541
- 4
- 2
-
-
3+1 The source of the information about the instances is the same as the answer by Brian. Someone might as well write C# code to get the value from the Windows Registry; which made me think the answer is redundant for moment but it's nice to know about xp_regread. #thanks. – Lzh Oct 29 '14 at 04:56
-
The query results are Instance Names only, Is it possible to add compatibility level for each instance to results? – Marwan Almukh Oct 22 '17 at 11:26
-
This won't differentiate between instances associated with a full version and an express version of SQL Server – Scott Howard Aug 13 '21 at 15:17
I know this thread is a bit old, but I came across this thread before I found the answer I was looking for and thought I'd share. If you are using SQLExpress (or localdb) there is a simpler way to find your instance names. At a command line type:
> sqllocaldb i
This will list the instance names you have installed locally. So your full server name should include (localdb)\ in front of the instance name to connect. Also, sqllocaldb allows you to create new instances or delete them as well as configure them. See: SqlLocalDB Utility.

- 361
- 3
- 4
If you just want to see what's installed on the machine you're currently logged in to, I think the most straightforward manual process is to just open the SQL Server Configuration Manager (from the Start menu), which displays all the SQL Services (and only SQL services) on that hardware (running or not). This assumes SQL Server 2005, or greater; dotnetengineer's recommendation to use the Services Management Console will show you all services, and should always be available (if you're running earlier versions of SQL Server, for example).
If you're looking for a broader discovery process, however, you might consider third party tools such as SQLRecon and SQLPing, which will scan your network and build a report of all SQL Service instances found on any server to which they have access. It's been a while since I've used tools like this, but I was surprised at what they found (namely, a handful of instances that I didn't know existed). YMMV. You might Google for details, but I believe this page has the relevant downloads: http://www.sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx
-
1SQL Server Configuration Manager was exactly what I needed. Quick and easy. – Christopher Jan 02 '11 at 02:57
SQL Server permits applications to find SQL Server instances within the current network. The SqlDataSourceEnumerator class exposes this information to the application developer, providing a DataTable containing information about all the visible servers. This returned table contains a list of server instances available on the network that matches the list provided when a user attempts to create a new connection, and expands the drop-down list containing all the available servers on the Connection Properties dialog box. The results displayed are not always complete. In order to retrieve the table containing information about the available SQL Server instances, you must first retrieve an enumerator, using the shared/static Instance property:
using System.Data.Sql;
class Program
{
static void Main()
{
// Retrieve the enumerator instance and then the data.
SqlDataSourceEnumerator instance =
SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
// Display the contents of the table.
DisplayData(table);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static void DisplayData(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
}
Console.WriteLine("============================");
}
}
}
from msdn http://msdn.microsoft.com/en-us/library/a6t1z9x2(v=vs.80).aspx

- 170
- 1
- 6
-
do I need to specify a subnet on this or domain, its coming back null for me, can you please update – Transformer Jan 07 '17 at 19:58
-
1For those looking to use .NET Core, `SqlDataSourceEnumerator` is not yet implemented, but is on the list to be added according to the [GitHub issue](https://github.com/dotnet/SqlClient/issues/17#issuecomment-498860154). – Daniel Hill Jun 24 '19 at 15:41
This query should get you the server name and instance name :
SELECT @@SERVERNAME, @@SERVICENAME
-
4This only tells you the name of the current instance associated with the executing query. OP requested a list of all the installed instances – Jay Walker Mar 19 '14 at 17:00
-
1This does not provide any information about which version of SQL server is installed – Ahmad Mar 01 '15 at 08:29
One more option would be to run SQLSERVER discovery report..go to installation media of sqlserver and double click setup.exe
and in the next screen,go to tools and click discovery report as shown below
This will show you all the instances present along with entire features..below is a snapshot on my pc

- 27,855
- 8
- 56
- 94
-
1This is the best way to get all the instances. None of the above high voted solutions can give a complete list as this method. It even shows MSSQL Express LocalDB versions installed in the computer even though it is not related to the original question about "Instances". – Dush Mar 11 '21 at 23:30
SQL Server Browser Service http://msdn.microsoft.com/en-us/library/ms181087.aspx

- 88,164
- 40
- 182
- 265
-
1oops... missing sqlbrowser.exe from usual location! I must have the Microsoft edition (ie the one that doesn't work) :-) Kidding - we all love Microsoft, almost as much as my mother-in-law. – Sam Feb 25 '11 at 05:47
From Windows command-line, type:
SC \\server_name query | find /I "SQL Server ("
Where "server_name" is the name of any remote server on which you wish to display the SQL instances.
This requires enough permissions of course.

- 7,131
- 5
- 49
- 74

- 51
- 1
- 1
-
Not working on my dev machine, which has 2008 R2 and multiple Express and LocalDB instances running. – Christoph Sep 13 '16 at 18:46
If you are interested in determining this in a script, you can try the following:
sc \\server_name query | grep MSSQL
Note: grep is part of gnuwin32 tools

- 2,479
- 20
- 32

- 51
- 1
- 1
-
3
-
You can also use, FIND, which leads to **sc \\server_name query | FIND "MSSQL"** – Julio Nobre Nov 21 '19 at 23:35
I had the same problem. The "osql -L" command displayed only a list of servers but without instance names (only the instance of my local SQL Sever was displayed). With Wireshark, sqlbrowser.exe (which can by found in the shared folder of your SQL installation) I found a solution for my problem.
The local instance is resolved by registry entry. The remote instances are resolved by UDP broadcast (port 1434) and SMB. Use "sqlbrowser.exe -c" to list the requests.
My configuration uses 1 physical and 3 virtual network adapters. If I used the "osql -L" command the sqlbrowser displayed a request from one of the virtual adaptors (which is in another network segment), instead of the physical one. osql selects the adpater by its metric. You can see the metric with command "route print". For my configuration the routing table showed a lower metric for teh virtual adapter then for the physical. So I changed the interface metric in the network properties by deselecting automatic metric in the advanced network settings. osql now uses the physical adapter.

- 21
- 1
The commands OSQL -L
and SQLCMD -L
will show you all instances on the network.
If you want to have a list of all instances on the server and doesn't feel like doing scripting or programming, do this:
- Start Windows Task Manager
- Tick the checkbox "Show processes from all users" or equivalent
- Sort the processes by "Image Name"
- Locate all
sqlsrvr.exe
images
The instances should be listed in the "User Name" column as MSSQL$INSTANCE_NAME
.
And I went from thinking the poor server was running 63 instances to realizing it was running three (out of which one was behaving like a total bully with the CPU load...)

- 1,159
- 15
- 9
I had this same issue when I was assessing 100+ servers, I had a script written in C# to browse the service names consist of SQL. When instances installed on the server, SQL Server adds a service for each instance with service name. It may vary for different versions like 2000 to 2008 but for sure there is a service with instance name.
I take the service name and obtain instance name from the service name. Here is the sample code used with WMI Query Result:
if (ServiceData.DisplayName == "MSSQLSERVER" || ServiceData.DisplayName == "SQL Server (MSSQLSERVER)")
{
InstanceData.Name = "DEFAULT";
InstanceData.ConnectionName = CurrentMachine.Name;
CurrentMachine.ListOfInstances.Add(InstanceData);
}
else
if (ServiceData.DisplayName.Contains("SQL Server (") == true)
{
InstanceData.Name = ServiceData.DisplayName.Substring(
ServiceData.DisplayName.IndexOf("(") + 1,
ServiceData.DisplayName.IndexOf(")") - ServiceData.DisplayName.IndexOf("(") - 1
);
InstanceData.ConnectionName = CurrentMachine.Name + "\\" + InstanceData.Name;
CurrentMachine.ListOfInstances.Add(InstanceData);
}
else
if (ServiceData.DisplayName.Contains("MSSQL$") == true)
{
InstanceData.Name = ServiceData.DisplayName.Substring(
ServiceData.DisplayName.IndexOf("$") + 1,
ServiceData.DisplayName.Length - ServiceData.DisplayName.IndexOf("$") - 1
);
InstanceData.ConnectionName = CurrentMachine.Name + "\\" + InstanceData.Name;
CurrentMachine.ListOfInstances.Add(InstanceData);
}

- 91
- 2
- 9
Will get the instances of SQL server reg query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
or Use SQLCMD -L

- 67
- 5
I just installed Sql server 2008, but i was unable to connect to any database instances. The commands @G Mastros posted listed no active instances.
So i looked in services and found that the SQL server agent was disabled. I fixed it by setting it to automatic and then starting it.

- 3,438
- 4
- 29
- 38
Here is a simple method: go to Start then Programs then Microsoft SQL Server 2005 then Configuration Tools then SQL Server Configuration Manager then SQL Server 2005 Network Configuration then Here you can locate all the instance installed onto your machine.
I know its an old post but I found a nice solution with PoweShell where you can find SQL instances installed on local or a remote machine including the version and also be extend get other properties.
$MachineName = ‘.’ # Default local computer Replace . with server name for a remote computer
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine’, $MachineName)
$regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL" )
$values = $regkey.GetValueNames()
$values | ForEach-Object {$value = $_ ; $inst = $regKey.GetValue($value);
$path = "SOFTWARE\\Microsoft\\Microsoft SQL Server\\"+$inst+"\\MSSQLServer\\"+"CurrentVersion";
#write-host $path;
$version = $reg.OpenSubKey($path).GetValue("CurrentVersion");
write-host "Instance" $value;
write-host "Version" $version}

- 1,043
- 1
- 10
- 11
-
hi this is great how, can I wrap this inside a C# class or how to call this from code – Transformer Jan 07 '17 at 19:59
-
Hi. This is my 1st attempt at powershell, so your help would be appreciated. I get the following error if I try and run this script. Aldo will this find all the remote sql servers? I am trying to compile a list of SQL Servers and their databases. You cannot call a method on a null-valued expression. + $values = $regkey.GetValueNames() – Darryl Wilson Mar 27 '19 at 12:49
A solution is to open SQL Server Management Studio on the local machine. When you connect to a server, you can choose "<Browse for more...>" :
The window "Browse for Servers" opens. In the tab "Local Servers", you can unfold "Database Engine" :

- 6,818
- 5
- 30
- 58
If your within SSMS you might find it easier to use:
SELECT @@Version
-
3The question itself states they do not want to/are not able to use SQL queries to determine the version – James T Sep 07 '15 at 12:40