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?

Rajkishore Sahoo is a Microsoft Azure consultant with more than 14 years of hands-on experience building cloud-native data solutions across Azure and AWS, focused on Azure SQL Database, Azure SQL Managed Instance, and the pipelines that connect them to production apps. Day to day, he provisions Azure SQL instances, configures firewalls and connection strings, tunes queries for cloud workloads, and wires databases into Azure Functions and Logic Apps. Read more