sp_query_store_reset_exec_stats (Transact-SQL)
Applies to:
SQL Server 2016 (13.x) and later
Azure SQL Database
Azure SQL Managed Instance
Clears the runtime stats for a specific query plan from the Query Store. If you enable Query Store for secondary replicas, sp_query_store_reset_exec_stats
can only be executed against the primary replica. The procedure's scope applies to the entire replica set.
Transact-SQL syntax conventions
Syntax
sp_query_store_reset_exec_stats [ @plan_id = ] plan_id [;]
Arguments
[ @plan_id = ] plan_id
Is the id of the query plan to being cleared. plan_id is a bigint, with no default.
Return Code Values
0 (success) or 1 (failure)
Permissions
Requires the ALTER permission on the database.
Examples
The following example returns information about the queries in the query store.
SELECT Txt.query_text_id, Txt.query_sql_text, Pl.plan_id, Qry.*
FROM sys.query_store_plan AS Pl
JOIN sys.query_store_query AS Qry
ON Pl.query_id = Qry.query_id
JOIN sys.query_store_query_text AS Txt
ON Qry.query_text_id = Txt.query_text_id ;
After you identify the plan_id that you want to clear the statistics, use the following example to delete the execution stats for a specific query plan. This example deletes the execution stats for plan number 3.
EXEC sp_query_store_reset_exec_stats 3;
Next steps
Learn more about Query Store in the following articles: