Seeing Procedure Execution Statistics in SQL Server
Hello to everyone,
In this article, I will try to give information about seeing Procedure Execution Statistics in SQL Server.
In SQL Server you may want to see Procedure Execution Statistics in some cases.
One advantage of Stored Procedures is that performance can be tracked. There may be many Stored Procedures in our database or SQL Server. You may want to see information such as how long they work, their working time, how much resources they use. This information shows us the information from the last run time of SQL Server to the time of writing the query. This information is kept in Memory and Cache. This information is lost when a restart is performed on SQL Server, but it is easy and useful to log the working information of historical Stored Procedures.
You can easily do this using the code below.
SELECT database_id,
object_id,
OBJECT_NAME(object_id, database_id) AS 'Prosedür Adı',
cached_time,
last_execution_time,
total_elapsed_time,
(total_elapsed_time / execution_count) AS 'AVG Elapsed Time',
last_elapsed_time,
execution_count
FROM sys.dm_exec_procedure_stats
WHERE database_id = DB_ID('AdventureWorks');
When you run the above code, you will see a result similar to the one below.
As you can see, we have seen the Procedure Execution Statistics.
Stored Procedure name, last run time, time elapsed when the procedure was run, how many times the procedure ran, etc. We were able to access information such as and show it in tabular form.
Good luck to everyone in business and life.