Monitor the running status of SQL statements in the database

Source: Internet
Author: User

When we are not using ADO. net for data interaction, but with some E/R database frameworks (such as nhib.pdf, LINQ to SQL, EF, etc.) for data interaction, it is often difficult to intuitively see the SQL statements executed in the database. At this time, we can only go to the database and execute some SQL statements to monitor the database operation. The following is an SQL monitoring script (applicable to SQL Server 2005)

 

Select creation_time n 'Statement compilation time'
, Last_execution_time n 'last execution time'
, Total_physical_reads n 'Total number of physical reads'
, Total_logical_reads/execution_count n 'number of logical reads per time'
, Total_logical_reads n 'Total number of logical reads'
, Total_logical_writes n' total number of logical writes'
, Execution_count n 'execution times'
, Total_worker_time/1000 n' total CPU time Ms'
, Total_elapsed_time/1000 n' total consumed time Ms'
, (Total_elapsed_time/execution_count)/1000 N 'average time Ms'
, Substring (St. Text, (Qs. statement_start_offset/2) + 1,
(Case statement_end_offset
When-1 then datalength (St. Text)
Else Qs. statement_end_offset end
-Qs. statement_start_offset)/2) + 1) n'execution statement'
From SYS. dm_exec_query_stats as Qs
Cross apply SYS. dm_exec_ SQL _text (Qs. SQL _handle) ST
Where substring (St. Text, (Qs. statement_start_offset/2) + 1,
(Case statement_end_offset
When-1 then datalength (St. Text)
Else Qs. statement_end_offset end
-Qs. statement_start_offset)/2) + 1) Not like '% fetch %'
Order by total_elapsed_time/execution_count DESC

 

Another articleArticleFive dynamic management objects in SQL Server 2005

This article will explain in detail the objects of database monitoring.

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.