View SQL statement execution time/test SQL statement Performance

Source: Internet
Author: User
Tags sql server query

The person who writes the program often needs to analyze whether the SQL statement that has been written has been optimized, and how fast the server responds, this time it needs to use the statistics state value of SQL to view it.

by setting Statistics we can view the system situation when executing SQL. The options are Profile,io, time. Introduced as follows:

SET STATISTICS profile on: Displays the time, in milliseconds, that is required to parse, compile, and execute the query.
SET STATISTICS IO on: Reports information about the number of scans per table referenced in the statement, the number of logical reads (pages accessed in the cache), and the number of physical reads (the number of times the disk was accessed).
Set STATISTICS time on: Displays the result set after each query execution, representing the configuration file that the query executes.

How 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 to start */
SELECT [TestCase] from [Testcaseselect]
GO/*--the end of your SQL script */
SET STATISTICS Profile OFF
SET STATISTICS IO OFF
SET STATISTICS Time OFF

Effect:

Alternatively, you can determine how efficient the SQL statement is by adding statements manually to calculate the execution time to see how much time is spent executing the statement:

DECLARE @d datetime
Set @d=getdate ()
/* Your SQL script starts */
SELECT [TestCase] from [Testcaseselect]
/* End of your SQL script */
Select [Statement execution takes time (milliseconds)]=datediff (Ms,@d,getdate ())

View SQL statement execution time/test SQL statement Performance

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: info-contact@alibabacloud.com 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.