SQL Flow Field Guide

sys.sp_query_store_set_hints

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

Creates or updates Query Store hints for a given query, allowing you to influence queries without changing application code or database objects.

What changes

Input
Not stated in the Microsoft summary.
Output or change
Creates or updates Query Store hints for a given query, allowing you to influence queries without changing application code or database objects.

Syntax at a glance

sp_query_store_set_hints
    [ @query_id = ] query_id ,
    [ @query_hints = ] 'query_hints'
    [ , [ @replica_group_id = ] 'replica_group_id' ]
[ ; ]

{ HASH | ORDER } GROUP
  | { CONCAT | HASH | MERGE } UNION
  | { LOOP | MERGE | HASH } JOIN
  | EXPAND VIEWS
  | FAST number_rows
  | FORCE ORDER
  | IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX
  | KEEP PLAN
  | KEEPFIXED PLAN
  | MAX_GRANT_PERCENT = percent
  | MIN_GRANT_PERCENT = percent
  | MAXDOP number_of_processors
  | NO_PERFORMANCE_SPOOL
  | OPTIMIZE FOR UNKNOWN
  | PARAMETERIZATION { SIMPLE | FORCED }
  | RECOMPILE
  | ROBUST PLAN
  | USE HINT ( '<hint_name>' [ , ...n ] )

Work example

Creates or updates Query Store hints for a given query, allowing you to influence queries without changing application code or database objects.

Write a proposed call on paper. Name the target, required permission, expected change, and recovery step before any lab use.

Check your work What can this procedure change or start, and what permission does it need?

Open Microsoft Learn for full syntax, permissions, and details for your version.