Use the query analyzer to adjust the SQL Server script _ PHP Tutorial

Source: Internet
Author: User
Use the query analyzer to adjust the SQL Server script. I like to think of the tools bundled with SQL servers as inverted pyramid. tools for diagnosing and checking general problems are at the top, and tools for finding and diagnosing specific areas of problems are at the bottom. Apart from mentioning that I like to regard the tools bundled with SQL Server as inverted pyramid, the tools for diagnosing and checking general problems are at the top, and the tools for finding and diagnosing specific areas of problems are at the bottom. In addition to providing a convenient way to write SQL scripts, the Query Analyzer still needs to use resources when you need to solve specific SQL scripts to identify problems. If you need to specify which query is holding the lock status of a specific table, you also want to use the query analyzer.
The key diagnostic feature of the query analyzer is that it can display the execution plan of a query. This execution plan will provide you with various types of useful information, such as how and when to use or not use indexes during query execution. It also provides many other details, such as sorting, parallelism, nested loops, and other things that the SQL Server must do when executing a specified query.
Benefits of the plan
With the query analyzer, you can view the expected plan without running the query itself, or view the actual plan after the query is executed. Obviously, the real plan is more accurate because it runs queries on the database physically. However, this method may not be the best choice for queries with huge system loads and/or long-term queries. In typical cases, when I think a specific query has a problem, or if I expect a query to be called frequently enough in the application to cause performance problems, I will run this tool.
You can enter the SQL expression in the query analyzer and press [Ctrl] L to view the expected execution plan. The execution plan is then displayed on the Results tab. The execution plan may be difficult to read at the beginning, because it does not read from left to right like English, but from right to left.
Running plan
Here is an example that you can follow. From this example, you can see how to use the query analyzer to view an execution plan. Consider the following query in the region. it returns the location and region of an employee from the Northwind database:

TerritoryDescription, RegionDescription
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
E. employeeid = 1
TerritoryDescription, RegionDescription

The result of this query shows that employee ID 1 has two regions in the East (Eastern), as shown in.


Query result

Bytes. Apart from mentioning...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.