使用 Windows 上的 SQL Server Management Studio (SSMS) 管理 Linux 上的 SQL ServerUse SQL Server Management Studio (SSMS) on Windows to manage SQL Server on Linux

本主题适用于: 是SQL Server (仅限 Linux)没有Azure SQL 数据库没有Azure SQL 数据仓库没有并行数据仓库 THIS TOPIC APPLIES TO: yesSQL Server (Linux only)noAzure SQL DatabasenoAzure SQL Data WarehousenoParallel Data Warehouse

这篇文章演示如何使用SQL Server Management Studio (SSMS)连接到 Linux 上的 SQL Server 2017。This article shows how to use SQL Server Management Studio (SSMS) to connect to SQL Server 2017 on Linux. SSMS 是一个 Windows 应用程序,因此请在 Windows 计算机可连接到 Linux 上的远程 SQL Server 实例时使用 SSMS。SSMS is a Windows application, so use SSMS when you have a Windows machine that can connect to a remote SQL Server instance on Linux.

成功连接后,请运行简单的 Transact - SQL (T-SQL) 查询,验证与数据库的通信。After successfully connecting, you run a simple Transact-SQL (T-SQL) query to verify communication with the database.

安装最新版本的 SQL Server Management StudioInstall the newest version of SQL Server Management Studio

使用 SQL Server 时,应始终使用最新版本的 SQL Server Management Studio (SSMS)。When working with SQL Server, you should always use the most recent version of SQL Server Management Studio (SSMS). 最新版本的 SSMS 不断更新和优化并且当前适用于 SQL Server 2017 on Linux。The latest version of SSMS is continually updated and optimized and currently works with SQL Server 2017 on Linux. 若要下载并安装最新版本,请参阅下载 SQL Server Management StudioTo download and install the latest version, see Download SQL Server Management Studio. 为保持使用最新版本,有可供下载的新版本时,最新版本的 SSMS 会发出提示。To stay up-to-date, the latest version of SSMS prompts you when there is a new version available to download.

连接到 Linux 上的 SQL ServerConnect to SQL Server on Linux

以下步骤演示了如何使用 SSMS 连接到 Linux 版 SQL Server 2017。The following steps show how to connect to SQL Server 2017 on Linux with SSMS.

  1. 启动 SSMS,通过键入Microsoft SQL Server Management Studio在窗口中搜索框中,并依次桌面应用程序。Start SSMS by typing Microsoft SQL Server Management Studio in the Windows search box, and then click the desktop app.

    SQL Server Management Studio

  2. 连接到服务器窗口中,输入以下信息 (如果已在运行 SSMS,请单击连接 > 数据库引擎以打开连接到服务器窗口):In the Connect to Server window, enter the following information (if SSMS is already running, click Connect > Database Engine to open the Connect to Server window):

    设置Setting DescriptionDescription
    服务器类型Server type 默认为数据库引擎;请勿更改此值。The default is database engine; do not change this value.
    服务器名称Server name 输入目标 Linux SQL Server 计算机的名称或它的 IP 地址。Enter the name of the target Linux SQL Server machine or its IP address.
    身份验证Authentication 在 Linux 上的 SQL Server 2017,对于使用SQL Server 身份验证For SQL Server 2017 on Linux, use SQL Server Authentication.
    登录Login 输入数据库服务器上具有权限的用户的名称 (例如,默认值SA安装过程中创建的帐户)。Enter the name of a user with access to a database on the server (for example, the default SA account created during setup).
    密码Password 为指定的用户输入密码 (为SA帐户,则此安装过程中创建)。Enter the password for the specified user (for the SA account, you created this during setup).

    SQL Server Management Studio: 连接到 SQL 数据库服务器

  3. 单击 “连接”Click Connect.

    提示

    如果连接失败,请首先尝试根据错误消息诊断问题。If you get a connection failure, first attempt to diagnose the problem from the error message. 然后查看连接故障排除建议Then review the connection troubleshooting recommendations.

  4. 已成功连接到你 SQL Sever 后对象资源管理器,你现在可以访问你的数据库执行管理任务或查询数据。After successfully connecting to your SQL Sever, Object Explorer opens and you can now access your database to perform administrative tasks or query data.

    对象资源管理器

运行示例查询Run sample queries

连接到服务器后,可以连接到数据库并运行示例查询。After you connect to your server, you can connect to a database and run a sample query. 如果你不熟悉如何编写查询,请参阅编写 TRANSACT-SQL 语句If you are new to writing queries, see Writing Transact-SQL Statements.

  1. 标识要使用的数据库,再次运行查询。Identify a database to use to run a query against. 这可能是您在创建新数据库TRANSACT-SQL 教程This could be a new database you created in the Transact-SQL tutorial. 也可能是AdventureWorks示例数据库,您下载并还原Or it could be the AdventureWorks sample database that you downloaded and restored.
  2. 对象资源管理器,导航到服务器上的目标数据库。In Object Explorer, navigate to the target database on the server.
  3. 右键单击数据库,然后选择新查询:Right-click the database and then select New Query:

    新查询。

  4. 在查询窗口中,编写 Transact - SQL 查询,从其中一个表中选择数据。In the query window, write a Transact-SQL query to select data from one of the tables. 下面的示例选择从数据Production.ProductAdventureWorks数据库。The following example selects data from the Production.Product table of the AdventureWorks database.

     SELECT TOP 10 Name, ProductNumber
     FROM Production.Product
     ORDER BY Name ASC
    
  5. 单击执行按钮:Click the Execute button:

    成功。

后续步骤Next steps

除查询外,还可使用 T-SQL 语句创建和管理数据库。In addition to queries, you can use T-SQL statements to create and manage databases.

如果你不熟悉 T-SQL 的请参阅教程: 编写 TRANSACT-SQL 语句TRANSACT-SQL 参考 (数据库引擎)If you're new to T-SQL, see Tutorial: Writing Transact-SQL Statements and the Transact-SQL Reference (Database Engine).

有关如何使用 SSMS 的详细信息,请参阅使用 SQL Server Management StudioFor more information on how to use SSMS, see Use SQL Server Management Studio.