Microsoft SQL Server Management Studio(SSMS)概述

介绍 (Introduction)

Microsoft SQL Server Server Management is an advanced development environment that enables us to configure, manage and administrate SQL Server database engines. SSMS is very popular and widely used by the database developers and administrators because of the following advantages:

Microsoft SQL Server服务器管理是一个高级开发环境,使我们能够配置,管理和管理SQL Server数据库引擎。 由于以下优点,SSMS受到数据库开发人员和管理员的广泛欢迎和广泛使用:

  • Cost-free

    免费用
  • Advanced user experience

    先进的用户体验
  • Various add-in options

    各种加载项选项
  • Easy installation

    简易安装

Firstly, we will learn the installation and then go through the other details of the SSMS.

首先,我们将学习安装方法,然后详细介绍SSMS的其他细节。

安装 (Installation)

We can download the latest version of the SSMS from the Microsoft download website and we can also find out the release notes.

我们可以从Microsoft下载网站下载最新版本的SSMS,也可以找到发行说明。

After downloading the setup file, we will open the setup file and click the install button in order to begin the installation. On this screen, the Location setting specifies the installation path of the Microsoft SQL Server Management Studio:

下载安装文件后,我们将打开安装文件并单击安装按钮以开始安装。 在此屏幕上,“ 位置”设置指定Microsoft SQL Server Management Studio的安装路径:

Starting installation of Microsoft SQL Server Management Studio

In the second screen, the installation process will be started and the progression of the setup will be shown:

在第二个屏幕中,将开始安装过程,并显示安装进度:

SSMS installation "Package Progress and Overall Progress" screen

After the installation is completed, the following screen will appear and inform us that the installation has been completed successfully:

安装完成后,将出现以下屏幕,并通知我们安装已成功完成:

SSMS installation "Setup Completed" screen

Now, we can launch SSMS from the Start menu:

现在,我们可以从“ 开始”菜单启动SSMS:

Starting Microsoft SQL Server Management Studio from the Start menu

Also, we can use the Command Prompt to launch SSMS:

另外,我们可以使用命令提示符来启动SSMS:

Starting Microsoft SQL Server Management Studio from Command Prompt

连接到数据库引擎 (Connecting to the Database Engine)

When we launch the SSMS, the Connect to Server dialog screen will appear in front of us. In this screen, we will set the Server name and Authentication type of the SQL Server which we want to connect to and then click the Connect button. In the following illustration, we will connect to a SQL Express edition with the SQL Server Authentication type. If we click on the Remember password option, SSMS will remember our username and password for the next connection of the same SQL Server instance:

当我们启动SSMS时,“ 连接到服务器”对话框屏幕将出现在我们前面。 在此屏幕中,我们将设置我们要连接SQL Server的服务器名称身份验证类型 ,然后单击“ 连接”按钮。 在下图中,我们将连接到具有SQL Server身份验证类型SQL Express版本。 如果单击“ 记住 密码”选项,SSMS将为同一SQL Server实例的下一次连接记住我们的用户名和密码:

Connect to a database through the SSMS

After a successful connection, the Object Explorer panel will appear on the left side of the main window of Microsoft SQL Server Management Studio.

成功连接后,“ 对象资源管理器”面板将出现在Microsoft SQL Server Management Studio主窗口的左侧。

On the Object Explorer, we can change various settings of the SQL Server Engine and deployed databases. This screen provides us to accomplish database related operations such as the backup, restore, detach, etc.:

对象资源管理器上 ,我们可以更改SQL Server Engine和已部署数据库的各种设置。 此屏幕为我们提供了完成与数据库相关的操作,例如备份,还原,分离等的操作:

Object Explorer right-click menu in Microsoft SQL Server Management Studio

At the same time, this screen helps us to maintain and manipulate the database objects.

同时,此屏幕可帮助我们维护和操作数据库对象。

Tip: Object Explorer Details panel helps us to find out more details about the server and database objects which are located under the selected folder. By default, this panel will be invisible, but we can open it under the View menu:

提示:“对象资源管理器的详细信息”面板可帮助我们找到有关位于所选文件夹下的服务器和数据库对象的更多详细信息。 默认情况下,该面板是不可见的,但是我们可以在“ 视图”菜单下将其打开:

Object Explorer Details panel in SSMS

For example, if we want to obtain more details about the tables which are contained by a particular database, selecting the tables folder will be enough to see these details. In addition, we can also add different data to this tabular list according to the type of the object. For example, it allows seeing the record number of rows for the tables:

例如,如果我们要获取有关特定数据库所包含的表的更多详细信息,则选择表文件夹将足以查看这些详细信息。 另外,我们还可以根据对象的类型将不同的数据添加到该列表中。 例如,它允许查看表的记录行数:

Showing tables row count in the Object Explorer Details

Microsoft SQL Server Management Studio上的查询编辑器 (Query Editor on Microsoft SQL Server Management Studio )

Another ability of the SSMS is that it enables to create and execute the T-SQL queries. When we click on the New Query button, which is placed on the toolbar, a new Query Editor will open. In this editor, we can create and execute SQL queries. In the following example, we will execute a very basic query that shows some of the synthetic customer data. First, we will open a new query editor window, type desired query and then, we will click the Execute button to run the query. The query result will be shown under the Results panel:

SSMS的另一个功能是,它可以创建和执行T-SQL查询。 当我们单击工具栏上的“ 新建查询”按钮时,将打开一个新的查询编辑器 。 在此编辑器中,我们可以创建和执行SQL查询。 在下面的示例中,我们将执行一个非常基本的查询,其中显示了一些综合客户数据。 首先,我们将打开一个新的查询编辑器窗口,键入所需的查询,然后单击执行按钮以运行查询。 查询结果将显示在“ 结果”面板下:

SELECT *
FROM(VALUES
(1, 
 'Gertie Michener', 
 'London'
),
(2, 
 'Colton Guion', 
 'New York'
),
(3, 
 'Ahmed Coty', 
 'Berlin'
),
(4, 
 'Devin Kimmons', 
 'Istanbul'
)) CustomerTable(Id, CustomerName, City)

Executing a query from the Query Editor

SSMS query editor offers various productivity options to programmers. In the previous example, the result set of the query has been shown on the grid, but we can change this option. On the SQL Editor toolbar, we can change this setting to Results to File, so that the result set of the query will be shown in a text format:

SSMS查询编辑器为程序员提供了各种生产力选项。 在前面的示例中,查询的结果集已显示在网格上,但是我们可以更改此选项。 在SQL编辑器工具栏上,我们可以将此设置更改为Results to File ,以便查询的结果集将以文本格式显示:

Query Results to Text

When we want to separate the query window and result set window, we need to enable the Display results in a separate taboption. To enable this option we need to follow the below steps:

当我们想分开查询窗口和结果集窗口时,我们需要启用“ 在单独的选项卡中显示结果”选项。 要启用此选项,我们需要执行以下步骤:

  • Click the Options command which is placed under the Tools menu:

    单击“ 工具”菜单下的“ 选项”命令:

    SSMS Option menu

  • Enable the Display results in a separate tab option under either Results to Grid tab or Results to Text tab:

    在“ 结果到网格”选项卡或“ 结果到文本”选项卡下启用“ 在单独的选项卡中显示结果”选项:

    Display results in a separate tab in SSMS

After enabling this option, the query results will be shown in a separate window. However, this option will be enabled when a new Query Window is opened. When we run the following query, the result set will be shown in the separate tab:

启用此选项后,查询结果将显示在单独的窗口中。 但是,当打开新的查询窗口时,将启用此选项。 当我们运行以下查询时,结果集将显示在单独的选项卡中:

Executing a query in the Query Editor

After the mentioned setting is changed, the query result will be shown as follows:

更改上述设置后,查询结果将显示如下:

Query Results in the Query Editor

The following illustration indicates the essential features of the SQL Editor toolbar:

下图说明了SQL编辑器工具栏的基本功能:

SQL Editor menu details

  1. Available Databases: In this drop-down menu, we can determine a database on which the query will be executed可用的数据库:在此下拉菜单中,我们可以确定要在其上执行查询的数据库
  2. Execute:This button starts the execution of a currently active query window执行:此按钮开始执行当前活动的查询窗口
  3. Cancel Executing Query:This button stops the execution of the query取消执行查询:此按钮停止执行查询
  4. Parse:This button validates the syntax of the query, but does not check the database objects解析:此按钮验证查询的语法,但不检查数据库对象
  5. Changing query result destination:In this button group, we can set the destination of the query result. It provides three different options: 更改查询结果的目的地:在此按钮组中,我们可以设置查询结果的目的地。 它提供了三种不同的选项:
    1. Results to Grid

      网格结果
    2. Results to Text

      结果文本
    3. Results to File

      结果存档
  6. Comment/Uncomment out the Selected Lines:

    Thesebuttons provide the option for commenting or uncommenting on the selected code lines:

    Commenting queries on the Query editor window in SSMS
  7. 注释/取消注释选定的行:

    这些 按钮提供了对选定代码行进行注释或取消注释的选项:

Tip:Some programmers wish to see the line numbers of the code in the query editor. Therefore, we need to follow the below steps:

提示:某些程序员希望在查询编辑器中查看代码的行号。 因此,我们需要遵循以下步骤:

  • Options command, which is placed under the 选项”命令,该命令位于“ Tools menu 工具”菜单下
  • General tab, which is placed under 常规”选项卡,该选项卡位于“ Transact-SQLnode Transact-SQL”节点下
  • Line numbers option 行号选项

The Line numbers option in the Options window of SSMS

After this setting change, the queries will be formatted as follows:

更改此设置后,查询的格式将如下所示:

Showing Line numbers in Query editor in SSMS

结论 (Conclusion)

In this article, we learned the basics of Microsoft SQL Server Management Studio and the following articles will help to improve SSMS-related skills :

在本文中,我们学习了Microsoft SQL Server Management Studio的基础知识,并且以下文章将有助于提高与SSMS相关的技能:

翻译自: https://www.sqlshack.com/overview-of-microsoft-sql-server-management-studio-ssms/