SQL Server to view the execution time of the statement

Source: Internet
Author: User
Tags getdate mssql server

The performance of the SQL statement is measured in MSSQL server by looking at the time it took to execute the SQL statement.

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.

Method one manual calculation

The time before execution is recorded, then the time after the execution of the SQL is recorded, and then the subtraction

Declare @d datetime Set @d = getdate ()/* your SQL script starts */* your SQL script ends */Select  [ statement execution takes time (milliseconds)]=DateDiff(MS,@d,  GetDate())

This method does not feel accurate enough, compared with the second method, the time display is longer, may be the operation time of the relevant function caused it

Method two using SQL to turn on the self-brought statistics

The steps taken when executing each statement are returned as rowsets, shown in the form of a hierarchy tree

SET STATISTICSProfile on SET STATISTICSIo on SET STATISTICSTime on GO/*--Your SQL script starts*/

/*your SQL script is over*/GO SET STATISTICSProfileOFF SET STATISTICSIoOFF SET STATISTICSTimeOFF

The 2nd method effects such as,

Method three with SQL Server comes with the tool

Location: Tools Options Query Execution Advanced

Effect

Original: http://www.cnblogs.com/wangguowen27/p/SqlServer_Select_wgw.html

Related:

http://blog.csdn.net/hj850126/article/details/7161028

Http://www.cnblogs.com/qanholas/archive/2011/05/06/2038543.html

SQL Server to view the execution time of the statement

Related Article

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.