This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11933|Reply: 0

[Source] How does MSSQL database check the execution efficiency of SQL statements?

[Copy link]
Posted on 1/11/2016 11:54:08 AM | | | |

The database that is commonly used in the website construction language ASP.NET MSSQL, how to check the execution time of SQL statements in the use of MSSQL, we will test it with SQL statements below, and get its execution efficiency, so that website coders can better grasp it. Our approach is to set STATISTICS so we can see what the system is like when executing SQL. The options are PROFILE, IO, TIME. The details are as follows:
SET STATISTICS PROFILE ON: Displays the time in milliseconds it takes to analyze, compile, and execute queries.
SET STATISTICS IO ON: Reports information about the number of scans, logical reads (pages accessed in the cache), and physical reads (the number of times disks were accessed) for each table referenced within the statement.
SET STATISTICS TIME ON: Displays the result set after each query is executed, representing the configuration file of the query execution.

To use: Open SQL SERVER Query Analyzer and enter the following statement:
SET STATISTICS PROFILE ON
SET STATISTICS IO ON
SET STATISTICS TIME ON
GO - your SQL script starts
SELECT [LastName] FROM [persons] - your own SQL statement
GO -- Your SQL script ends
SET STATISTICS PROFILE OFF
SET STATISTICS IO OFF
SET STATISTICS TIME OFF
   After using the above code, it will be executed to get a result display page, and you can find the corresponding answer in the result display.


SQL Server parse and compile time:
   CPU time = 0 ms, elapsed time = 5 ms.

(1 row(s) affected)
Table 'sp_UserAssets'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'sp_RealNameAuthentication'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'sp_UserInfo'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(6 row(s) affected)

(1 row(s) affected)

SQL Server Execution Times:
   CPU time = 16 ms,  elapsed time = 384 ms.
SQL Server parse and compile time:
   CPU time = 0 ms, elapsed time = 0 ms.

SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 0 ms.





Previous:asp.net get the local virtual path after removing the domain name
Next:Tutorial for downloading and installing Python for the first time (taking Python 3.5.1 as an example)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com