查找安装了多少 SQL Server 实例

adi*_*med 2 sql-server sql-server-2012

在 SQL Server 2012 实例上,如何使用 SQL 查询获取 SQL Server 实例的名称?

我想显示当前安装在 SQL Server 中的实例名称。

Jul*_*eur 7

以下是一些使用安装了 Windows Server 和 SQL Server 的服务器上已有的选项。

您可以列出名称以SQL Server (...以下开头的服务器上的服务:

sc \\IP_or_Name query | find /I "SQL Server ("
Run Code Online (Sandbox Code Playgroud)

IP_or_Name 是 Windows Server 20xx 服务器的 IP 或 DNS 名称。

或者使用 Powershell:

Get-Service | Where-Object {$_.DisplayName -like "SQL Server (*"}
Run Code Online (Sandbox Code Playgroud)

您可以HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL使用 Regedit查看注册表项的内容。

您还可以使用 Powershell:

Get-ItemProperty 'HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL'
Run Code Online (Sandbox Code Playgroud)

KeyHKLM:\Software\Microsoft\Microsoft SQL Server\InstalledInstances给出了一个由换行符分隔的名称列表。


Powershell 命令可以使用Invoke-Command远程执行:

Invoke-Command -ComputerName computer -ScriptBlock { command } -Credential username
Run Code Online (Sandbox Code Playgroud)

使用sqlcmd您可以获得在网络上广播其名称的实例列表:

sqlcmd -L
Run Code Online (Sandbox Code Playgroud)

或者使用具有显示版本号优势的 Powershell:

[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()
Run Code Online (Sandbox Code Playgroud)