Recently, I got the requirement to check one of the stored procedure execution times in my SQL server database. This article will help you check the stored procedure execution history in an SQL Server.
How To Check Stored Procedure Execution History In SQL Server
To check stored procedure execution history in SQL server, follow the below two simple approaches.
Approach-1: Using sys.dm_exec_query_stats
We can query the sys.dm_exec_query_stats to get the details of the execution history of any stored procedure. Let us execute the SQL query below. Here, the SelectAllProducts is the name of the stored procedure.
SELECT
qs.execution_count,
qs.last_execution_time
FROM
sys.dm_exec_query_stats qs
CROSS APPLY
sys.dm_exec_sql_text(qs.sql_handle) qt
WHERE
qt.text LIKE '%SelectAllProducts%'
ORDER BY
qs.last_execution_time DESC;
After executing the above query, I got the stored procedure execution details as shown in the screenshot below.

Check out SQL Server Stored Procedure Naming Convention and Best Practices
Approach-2: Using sys.dm_exec_procedure_stats
We can also query the sys.dm_exec_procedure_stats for this purpose.
SELECT
OBJECT_NAME(object_id) AS ProcedureName,
execution_count,
last_execution_time
FROM
sys.dm_exec_procedure_stats
ORDER BY
last_execution_time DESC;
After executing the above query, I got the expected output as shown below.

Conclusion
Tracking the stored procedure execution details in an SQL server is crucial when working as a developer or as an SQL DBA. You can execute any of the SQL queries mentioned in this article.
You may also like following the articles below.
- How to Find Stored Procedure in SQL Server
- How To Save Stored Procedure In SQL Server
- Find Stored Procedure by Name in SQL Server
- ALTER Stored Procedure in SQL Server
- How to Execute the Stored Procedure for Updating the SQL Server?
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.