Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.48 KB

File metadata and controls

91 lines (68 loc) · 3.48 KB
title sp_query_store_reset_exec_stats (Transact-SQL)
description Clears the runtime stats for a specific query plan from the Query Store.
author markingmyname
ms.author maghan
ms.reviewer randolphwest
ms.date 11/17/2025
ms.service sql
ms.subservice system-objects
ms.topic reference
ms.custom
ignite-2025
f1_keywords
sp_query_store_reset_exec_stats_TSQL
sys.sp_query_store_reset_exec_stats_TSQL
sys.sp_query_store_reset_exec_stats
sp_query_store_reset_exec_stats
helpviewer_keywords
sp_query_store_reset_exec_stats
sys.sp_query_store_reset_exec_stats
dev_langs
TSQL
monikerRange =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb

sp_query_store_reset_exec_stats (Transact-SQL)

[!INCLUDE sqlserver2016-asdb-asdbmi-fabricsqldb]

Clears the runtime stats for a specific query plan from the Query Store.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_query_store_reset_exec_stats [ @plan_id = ] plan_id
[ ; ]

Arguments

[!INCLUDE extended-stored-procedures]

[ @plan_id = ] plan_id

The ID of the query plan to be cleared. @plan_id is bigint, with no default.

Return code values

0 (success) or 1 (failure).

Permissions

Requires the ALTER permission on the database.

Remarks

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. Query Store for secondary replicas is supported starting in [!INCLUDE sssql25-md] and later versions, and in Azure SQL Database. For complete platform support, see Query Store for secondary replicas.

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
     INNER JOIN sys.query_store_query AS qry
         ON pl.query_id = qry.query_id
     INNER 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.

EXECUTE sp_query_store_reset_exec_stats 3;

Related content