SSMS 实用工具SSMS Utility

适用对象:SQL Server 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 是并行数据仓库APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

Ssms 实用工具打开 SQL Server Management StudioSQL Server Management StudioThe Ssms utility opens SQL Server Management StudioSQL Server Management Studio. 如果指定, Ssms 还可以与服务器建立连接并打开查询、脚本、文件、项目和解决方案。If specified, Ssms also establishes a connection to a server, and opens queries, scripts, files, projects, and solutions.

可以指定包含查询、项目或解决方案的文件。You can specify files that contain queries, projects, or solutions. 如果提供了连接信息并且文件类型与服务器类型关联,则包含查询的文件将自动连接到该服务器。Files that contain queries are automatically connected to a server if connection information is provided and the file type is associated with that type of server. 例如,.sql 文件在 SQL Server Management StudioSQL Server Management Studio 中打开一个 SQL 查询编辑器窗口,.mdx 文件在 SQL Server Management StudioSQL Server Management Studio 中打开一个 MDX 查询编辑器窗口。For instance, .sql files open a SQL Query Editor window in SQL Server Management StudioSQL Server Management Studio, and .mdx files open an MDX Query Editor window in SQL Server Management StudioSQL Server Management Studio. SQL Server 解决方案和项目 在 SQL Server Management StudioSQL Server Management Studio 中打开。SQL Server Solutions and Projects open in SQL Server Management StudioSQL Server Management Studio.

备注

Ssms 实用工具不能运行查询。The Ssms utility does not run queries. 若要从命令行运行查询,请使用 sqlcmd 实用工具。To run queries from the command line, use the sqlcmd utility.

语法Syntax

Ssms 
[scriptfile] [projectfile] [solutionfile] 
[-S servername] [-d databasename] [-G] [-U username] [-E] [-nosplash] [-log [filename]?] [-?] 

参数Arguments

scriptfile 指定一个或多个要打开的脚本文件 。scriptfile Specifies one or more script files to open. 该参数必须包含文件的完整路径。The parameter must contain the full path to the files.

projectfile 指定要打开的脚本项目 。projectfile Specifies a script project to open. 该参数必须包含脚本项目文件的完整路径。The parameter must contain the full path to the script project file.

solutionfile 指定要打开的解决方案 。solutionfile Specifies a solution to open. 该参数必须包含解决方案文件的完整路径。The parameter must contain the full path to the solution file.

[ -S servername] 服务器名称[-S servername] Server name

[ -d databasename] 数据库名称[-d databasename] Database name

[-G ] 使用 Active Directory 身份验证进行连接。[-G] Connect using Active Directory Authentication. 连接类型的确定取决于是否包含 -U 。The type of connection is determined whether -U is included.

备注

当前不支持“Active Directory - 含 MFA 支持的通用身份验证” 。Active Directory - Universal with MFA support is not currently supported.

[ -U username] 通过“SQL 身份验证”进行连接时的用户名[-U username] User name when connecting with 'SQL Authentication'

[-E] 使用 Windows 身份验证进行连接 [-E] Connect using Windows Authentication

[-nosplash] 阻止 SQL Server Management StudioSQL Server Management Studio 在打开时显示初始屏幕 。[-nosplash] Prevents SQL Server Management StudioSQL Server Management Studio from displaying the splash screen graphic while opening. 在带宽有限的情况下,通过终端服务连接到运行 SQL Server Management StudioSQL Server Management Studio 的计算机上时,使用此选项。Use this option when connecting to the computer running SQL Server Management StudioSQL Server Management Studio by means of Terminal Services over a connection with a limited bandwidth. 该参数不区分大小写,并且可放在其他参数前后This argument is not case-sensitive and may appear before or after other arguments

[-log[filename]?] 将 SQL Server Management StudioSQL Server Management Studio 活动记录到指定的文件中以便进行故障排除 [-log[filename]?] Logs SQL Server Management StudioSQL Server Management Studio activity to the specified file for troubleshooting

[-?] 显示命令行帮助 [-?] Displays command-line help

备注Remarks

上述所有开关都是可选的,并用空格分隔,但文件用逗号分隔。All of the switches are optional and separated by a space except files, which are separated by commas. 如果不指定任何开关,则 Ssms 将按照“工具” 菜单的“选项” 设置中指定的方式打开 SQL Server Management StudioSQL Server Management StudioIf you do not specify any switches, Ssms opens SQL Server Management StudioSQL Server Management Studio as specified in the Options settings on the Tools menu. 例如,如果“环境/常规” 页的“启动时” 选项指定了“打开新查询窗口” ,Ssms 则会在打开时显示一个空白查询编辑器。For example, if the Environment/General page At startup option specifies Open new query window, Ssms opens with a blank Query Editor.

-log 开关必须出现在命令行的末尾,位于所有其他开关的后面。The -log switch must appear at the end of the command line, after all, other switches. 文件名参数是可选的。The filename argument is optional. 如果指定了一个文件名,并且该文件不存在,则创建该文件。If a filename is specified, and the file does not exist, the file is created. 如果无法创建该文件(例如,由于没有足够的写访问权限),日志将改为写入非本地化的 APPDATA 位置(见下文)。If the file cannot be created - for example, due to insufficient write access, the log is written to the nonlocalized APPDATA location instead (See below). 如果未指定该文件名参数,则两个文件将写入当前用户的非本地化的应用程序数据文件夹。If the filename argument is not specified, two files are written to the current user's nonlocalized application data folder. SQL Server 的非本地化的应用程序数据文件夹可以从 APPDATA 环境变量中找到。The nonlocalized application data folder for SQL Server can be found from the APPDATA environment variable. 例如,对于 SQL Server 2012,文件夹为 <system drive>:\Users\<username>\AppData\Roaming\Microsoft\AppEnv\10.0\。For example, for SQL Server 2012, the folder is <system drive>:\Users\<username>\AppData\Roaming\Microsoft\AppEnv\10.0\. 默认情况下,这两个文件分别命名为 ActivityLog.xml 和 ActivityLog.xsl。The two files are, by default, named ActivityLog.xml and ActivityLog.xsl. 前者包含活动日志数据,后者是一种 XML 样式表,提供了更方便的方法来查看 XML 文件。The former contains the activity log data, and the latter is an XML style sheet, which provides a more convenient way to view the XML file. 按照下列步骤操作,在默认 XML 查看器(如 Internet Explorer)中查看日志文件:依次单击“开始”和“运行...”,在提供的字段中键入“<system drive>:\Users\<username>\AppData\Roaming\Microsoft\AppEnv\10.0\ActivityLog.xml”,再按 Enter。Use the following steps to view the log file in your default XML viewer, like Internet Explorer: Click Start, then click Run...", then type "<system drive>:\Users\<username>\AppData\Roaming\Microsoft\AppEnv\10.0\ActivityLog.xml" into the field provided, and then press Enter.

如果提供了连接信息并且文件类型与服务器类型关联,则包含查询的文件会立即连接到该服务器。Files that contain queries prompt to be connected to a server if connection information is provided and the file type is associated with that type of server. 例如,.sql 文件在 SQL Server Management StudioSQL Server Management Studio 中打开一个 SQL 查询编辑器窗口,.mdx 文件在 SQL Server Management StudioSQL Server Management Studio 中打开一个 MDX 查询编辑器窗口。For instance, .sql files open a SQL Query Editor window in SQL Server Management StudioSQL Server Management Studio, and .mdx files open an MDX Query Editor window in SQL Server Management StudioSQL Server Management Studio. SQL Server 解决方案和项目 在 SQL Server Management StudioSQL Server Management Studio 中打开。SQL Server Solutions and Projects open in SQL Server Management StudioSQL Server Management Studio.

下表列出了与服务器类型相对应的文件扩展名。The following table maps server types to file extensions.

服务器类型Server type 分机Extension
SQL ServerSQL Server .sql.sql
SQL Server Analysis ServicesSQL Server Analysis Services .mdx.mdx

.xmla.xmla

示例Examples

以下脚本将在命令指示符下使用默认设置打开 SQL Server Management StudioSQL Server Management StudioThe following script opens SQL Server Management StudioSQL Server Management Studio from a command prompt with the default settings:

Ssms

以下脚本在命令提示符下使用“Active Directory - 集成” 打开 SQL Server Management StudioSQL Server Management StudioThe following scripts opens SQL Server Management StudioSQL Server Management Studio from a command prompt using Active Directory - Integrated:

Ssms.exe -S servername.database.windows.net -G

以下脚本将在命令指示符下,使用 Windows 身份验证打开 SQL Server Management StudioSQL Server Management Studio ,其中代码编辑器设置为 ACCTG and the database AdventureWorks2012, ,并且不显示初始屏幕:The following script opens SQL Server Management StudioSQL Server Management Studio from a command prompt, with Windows Authentication, with the Code Editor set to the server ACCTG and the database AdventureWorks2012, without showing the splash screen:

Ssms -E -S ACCTG -d AdventureWorks2012 -nosplash

以下脚本将在命令指示符下打开 SQL Server Management StudioSQL Server Management Studio ,并打开 MonthEndQuery 脚本。The following script opens SQL Server Management StudioSQL Server Management Studio from a command prompt, and opens the MonthEndQuery script.

Ssms "C:\Documents and Settings\username\My Documents\SQL Server Management Studio Projects\FinanceScripts\FinanceScripts\MonthEndQuery.sql"

以下脚本在命令指示符下打开 SQL Server Management StudioSQL Server Management Studio ,并打开名为 developer的计算机上的 NewReportsProject 项目:The following script opens SQL Server Management StudioSQL Server Management Studio from a command prompt, and opens the NewReportsProject project on the computer named developer:

Ssms "\\developer\fin\ReportProj\ReportProj\NewReportProj.ssmssqlproj"

以下脚本在命令提示符下打开 SQL Server Management StudioSQL Server Management Studio ,并打开 MonthlyReports 解决方案:The following script opens SQL Server Management StudioSQL Server Management Studio from a command prompt, and opens the MonthlyReports solution:

Ssms "C:\solutionsfolder\ReportProj\MonthlyReports.ssmssln"

另请参阅See Also

使用 SQL Server Management StudioUse SQL Server Management Studio