我喜欢把SQL服务器所捆绑的工具看作是倒金字塔型的,诊断和检查一般问题的工具在顶端,寻找和诊断问题具体区域的工具在底部。除了提供一种编写SQL脚本的便捷方式之外,在你需要解决特定SQL脚本里明确问题的时候,查询分析器(Query Analyzer)还是所需要使用的资源。如果你需要指出哪个查询正在保持着某个特定表格的锁定状态,你也会希望使用查询分析器。
查询分析器的关键诊断特性是它能够显示某个查询的执行计划。这个执行计划会向你提供各种类型的有用信息,例如在查询的执行期间如何以及何时使用或者不使用索引。它还会提供许多其他的细节,例如排序、平行(parallelism)、嵌套循环,以及SQL服务器在执行指定查询时必须做的其他事情。
计划的好处
有了查询分析器,你就可以查看预计计划而不需要运行查询本身,或者在查询执行之后查看真实的计划。很显然,真实的计划会更加准确,因为它是从物理上对数据库运行查询的。但是对于系统负载巨大和/或长期的查询,这种方法可能就不是最好的选择了。在典型情况下,当我认为某个特定的查询有问题的时候,或者如果我预计有一个查询会在应用程序里被足够频繁地调用以至于可能会导致性能问题的时候,我就会运行这个工具。
你可以通过把SQL表达式输入查询分析器再按[Ctrl]L来查看预计的执行计划。执行计划然后就会显示在结果(Results)面板的选项卡里。执行计划在刚开始的时候可能比较难读,因为它不像英语一样是从左往右读的,而是从右往左读的。
运行中的计划
这里有一个你可以跟着做的例子,从这个例子里你可以看到如何使用查询分析器来查看一个执行计划。考虑一下下面查询,它会从Northwind数据库里返回某个雇员所在的地点和相关地区:
SELECT
TerritoryDescription, RegionDescription
FROM
Employees e
JOIN EmployeeTerritories et ON e.employeeid = et.employeeid
JOIN Territories t ON et.territoryid = t.territoryid
JOIN Region r ON t.regionid = r.regionid
WHERE
e.employeeid = 1
ORDER BY
TerritoryDescription, RegionDescription
这个查询的结果显示:一号EmployeeId在东部(Eastern)有两个地区,如图A所示。
图A
查询结果

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)