Skip to content

Latest commit

 

History

History
84 lines (64 loc) · 3.09 KB

sp-query-store-reset-exec-stats-transact-sql.md

File metadata and controls

84 lines (64 loc) · 3.09 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
sp_query_store_reset_exec_stats (Transact-SQL)
Clears the runtime stats for a specific query plan from the Query Store.
markingmyname
maghan
randolphwest
03/07/2025
sql
system-objects
reference
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
sp_query_store_reset_exec_stats
sys.sp_query_store_reset_exec_stats
TSQL
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

sp_query_store_reset_exec_stats (Transact-SQL)

[!INCLUDE sqlserver2016-asdb-asdbmi]

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.

:::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.

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.

EXEC sp_query_store_reset_exec_stats 3;

Related content