SQL 窗格 (Visual Database Tools)SQL Pane (Visual Database Tools)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

您可以使用 SQL 窗格创建自己的 SQL 语句,也可以使用“条件”窗格和“关系图”窗格创建语句,在后面这种情况下将在 SQL 窗格中相应地创建 SQL 语句。You can use the SQL pane to create your own SQL statement, or you can use the Criteria pane and Diagram pane to create the statement, in which case the SQL statements will be created in the SQL pane. 生成查询时,SQL 窗格将自动更新并重新设置格式以便于阅读。As you build your query, the SQL pane automatically updates and reformats for easy readability.

若要打开 SQL 窗格,请首先打开查询和视图设计器(在服务器资源管理器中选择相应的数据库对象后,在“数据库”**** 菜单中单击“新建查询”****)。To open the SQL pane, first open Query and View Designer (with a database object selected in Server Explorer, from the Database menu, click New Query). 然后在“查询设计器”**** 菜单中指向“窗格”****,再单击“SQL”****。Then from the Query Designer menu point to Pane and click SQL.

在 SQL 窗格中,可以进行以下操作:In the SQL pane you can:

  • 通过输入 SQL 语句创建新查询。Create new queries by entering SQL statements.

  • 根据在“关系图”窗格和“条件”窗格中进行的设置,对查询和视图设计器创建的 SQL 语句进行修改。Modify the SQL statement created by the Query and View Designer based on settings you make in the Diagram and Criteria panes.

  • 输入语句以利用所使用数据库的特有功能。Enter statements that take advantage of features specific to the database you are using.

备注

请务必了解所用数据库中数据库对象的标识规则。Be sure you know the rules for identifying database objects in the database you are using. 有关详细信息,请参阅数据库管理系统文档。For details, see the documentation for your database management system.

SQL 窗格中的语句Statements in the SQL Pane

您可以直接在 SQL 窗格中编辑当前查询。You can edit the current query directly in the SQL pane. 当移动到另一窗格时,查询和视图设计器会自动设置语句格式,再更改“关系图”窗格和“条件”窗格以同语句匹配。When you move to another pane, the Query and View Designer automatically formats your statement, and then changes the Diagram and Criteria panes to match your statement.

如果语句不能在“关系图”窗格和“条件”窗格中表示出来,并且这两个窗格是可见的,则查询和视图设计器将显示一条错误信息,然后提供两种选择:If your statement cannot be represented in the Diagram and Criteria panes, and if those panes are visible, Query and View Designer displays an error and then offers you two choices:

  • 忽略无法在“关系图”窗格和“条件”窗格中表示的语句。Ignore that the statement can not be represented in the Diagram and Criteria panes.

  • 撤销无法表示的更改,并恢复到最近的 SQL 语句版本。Undo the change that can not be represented and revert to the most recent version of the SQL statement.

如果选择忽略无法在“关系图”窗格和“条件”窗格中表示的语句,查询和视图设计器将使其他窗格变成灰色,指示它们不再反映 SQL 窗格的内容。If you choose to ignore that the statement can not be represented in the Diagram and Criteria panes, the Query and View Designer dims the other panes to indicate that they no longer reflect the contents of the SQL pane.

您可以继续编辑语句,并像执行任何 SQL 语句一样执行该语句。You can continue to edit the statement and execute it as you would any SQL statement.

备注

如果输入 SQL 语句,但随后通过更改“关系图”窗格和“条件”窗格对查询做进一步更改,则查询和视图设计器将重新生成和显示 SQL 语句。If you enter an SQL statement, but then make further changes to the query by changing the Diagram and Criteria panes, the Query and View Designer rebuilds and redisplays the SQL statement. 在某些情况下,此操作产生的 SQL 语句在构造上和原先输入的 SQL 语句将有所不同(尽管该语句始终会产生相同的结果)。In some cases, this action results in an SQL statement that is constructed differently from the one you originally entered (though it will always yield the same results). 当使用的搜索条件涉及用 AND 和 OR 链接的多个子句时,尤其可能产生这种差异。This difference is particularly likely when you are working with search conditions that involve several clauses linked with AND and OR.

另请参阅See Also

创建查询 (Visual Database Tools)Create Queries (Visual Database Tools)
运行查询 (Visual Database Tools)Run Queries (Visual Database Tools)
设计查询和视图操作指南主题 (Visual Database Tools)Design Queries and Views How-to Topics (Visual Database Tools)
“关系图”窗格 (Visual Database Tools)Diagram Pane (Visual Database Tools)
“条件”窗格 (Visual Database Tools)Criteria Pane (Visual Database Tools)
“结果”窗格 (Visual Database Tools)Results Pane (Visual Database Tools)