I just saw an SQL statement to share with you.
This SQL statement allows you to view the statements that take the longest time in a database and the number of executions in a certain period of time.
Copy the following statement to the production database for execution,
The results help us analyze the pages on which the system is most frequently used and which SQL statements need to be optimized.
It is helpful for system usage and performance tuning.
Thanks,
Aden
Declare @ skssj varchar (23 ),
@ Sjssj varchar (23)
Set @ skssj = '2017-02-01 01:35:00. 000'
Set @ sjssj = '2017-02-01 23:00:00. 000'
Select
(Total_elapsed_time/execution_count)/1000 N 'average time Ms'
, Total_elapsed_time/1000 n' total consumed time Ms'
, Total_worker_time/1000 n' total CPU time Ms'
, 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'
, 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'
, Creation_time n 'Statement compilation time'
, Last_execution_time n 'last execution time'
From
SYS. dm_exec_query_stats as QS cross apply SYS. dm_exec_ SQL _text (Qs. SQL _handle) as 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 %'
And creation_time between @ skssj and @ sjssj
Order
Total_elapsed_time/execution_count DESC;