快速回答
只需运行以下命令:
{InstanceHome}\MSSQL\Binn\sqlservr.exe -v [-s InstanceName]
NOTE ABOUT SQL Server Express LocalDB: LocalDB can only be determined by the
existence of the following folder:
C:\Program Files\Microsoft SQL Server\{SQL Server Version: 110, 120, etc}\LocalDB\Binn
Running "sqlserver.exe -v" doesn't help as it reports as being "Developer Edition", and
searching the Registry it reports as being "Express Edition".
与其他在以下情况下不起作用的解决方案不同,此方法始终有效:
- 您不想编写程序(例如PowerShell)?
- 客户端工具尚未安装(需要使用SQLCMD.EXE)吗?
- 没有SQL Server日志文件,或者没有包含任何启动/重新启动事件的日志文件?
- SQL Server未运行(因此
SELECT @@VERSION;
无法选择)?
示例1
如果仅安装了一个实例,则无需使用该-s
开关:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn>sqlservr.exe -v
返回值:
2015-08-01 11:40:11.63 Server Logging to event log is disabled. Startup option '-v' is supplied, either from the registry or the command prompt.
2015-08-01 11:40:11.63 Server Microsoft SQL Server 2012 - 11.0.5343.0 (X64)
May 4 2015 19:11:32
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
2015-08-01 11:40:11.63 Server (c) Microsoft Corporation.
2015-08-01 11:40:11.63 Server All rights reserved.
2015-08-01 11:40:11.63 Server Server process ID is 3824.
2015-08-01 11:40:11.63 Server System Manufacturer: '{CompanyName}', System Model: '{ModelNumber}'.
2015-08-01 11:40:11.63 Server Authentication mode is MIXED.
2015-08-01 11:40:11.63 Server The service account is '{AccountName}'. This is an informational message; no user action is required.
2015-08-01 11:40:11.63 Server SQL Server shutdown has been initiated
示例2
如果您在计算机上安装了多个实例,则还需要使用-s
开关来指定您对哪个实例感兴趣,否则它可以混合版本信息:
C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS2014\MSSQL\Binn>sqlservr.exe -v
-s SQLEXPRESS2014
返回值:
2015-08-01 12:01:13.13 Server Logging to event log is disabled. Startup option '-v' is supplied, either from the registry or the command prompt.
2015-08-01 12:01:13.13 Server Microsoft SQL Server 2014 - 12.0.4213.0 (X64)
Jun 9 2015 12:06:16
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
2015-08-01 12:01:13.13 Server UTC adjustment: -4:00
2015-08-01 12:01:13.13 Server (c) Microsoft Corporation.
2015-08-01 12:01:13.13 Server All rights reserved.
2015-08-01 12:01:13.13 Server Server process ID is 1712.
2015-08-01 12:01:13.13 Server System Manufacturer: '{CompanyName}', System Model: '{ModelNumber}'.
2015-08-01 12:01:13.13 Server Authentication mode is WINDOWS-ONLY.
2015-08-01 12:01:13.13 Server The service account is '{AccountName}'. This is an informational message; no user action is required.
2015-08-01 12:01:13.13 Server SQL Server shutdown has been initiated
附加信息
确定程序版本信息的最快,最简单,最可靠的方法就是简单地从程序中请求该信息。大多数程序(* .COM和* .EXE)都有一个命令行开关/标志/参数/选项/ Dealy-ma-bob,它将显示帮助和/或版本信息。
根据程序本身,命令行开关将以以下之一为前缀:
并且,再次取决于程序本身,命令行开关将为以下之一:
{以上显示的SQL Server示例}
另一方面,命令行实用程序SQLCMD.EXE使用该-v
开关将变量值传递到SQL脚本中,因此它仅在其常规信息显示中显示版本信息:
C:\>sqlcmd /?
Microsoft (R) SQL Server Command Line Tool
Version 11.0.2100.60 NT x64
Copyright (c) 2012 Microsoft. All rights reserved.
usage: Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
...
[-v var = "value"...] ...
...
[-? show syntax summary]
但是,NotePad仅具有非常有限的一组命令行开关,并且它们都不显示版本信息。
可选的简便方法:
检查注册表:
密钥:HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ {VersionNumber} \ Tools \ Setup
名称:版本
如果知道版本号(例如,SQL Server 2012 = 110,SQL Server 2014 = 120等),则可以通过在命令提示符处运行以下命令来专门为其指定版本:
REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\{VersionNumber}\Tools\Setup" /v /e /f Edition
返回类似于以下内容的一项:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup
Edition REG_SZ Developer Edition
如果您看到该版本的安装版本,请在命令提示符处运行以下命令:
REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server" /s /v /e /f Edition
返回一个或多个与上面和下面显示的条目相似的条目:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11E.LOCALDB\Setup
Edition REG_SZ Express Edition
检查安装日志:
C:\ Program Files \ Microsoft SQL Server \ {SQL Server版本:110、120等} \ Setup Bootstrap \ Log \ {date_time} \ Detail.txt
对于字符串“ IsExpressSku”:
(03)2014-09-05 16:53:44 SQLEngine:--EffectiveProperties:IsExpressSku = True