ALTER DATABASE MyDatabase SET QUERY_STORE = ON;
Topics
43
Aggregate Functions & GROUP BY
Always On Availability Groups
Backup & Recovery
Change Data Capture (CDC)
Columnstore Indexes
Common Table Expressions (CTEs)
Constraints (Primary Key, Foreign Key, Check & Unique)
Cursors
Data Types & Schema Design
Deadlocks
Dynamic Data Masking
Dynamic SQL
Error Handling with TRY CATCH
Full Text Search
Hash Indexes & Hash Join Operations
Indexes
In-Memory OLTP (Memory-Optimized Tables)
Isolation & Locking
Joins
JSON Support in SQL Server
Linked Servers
Merge Statement (Upsert)
Normalization
Partitioning
Pivoting & Unpivoting Data
Query Optimization & Plans
Query Store
Replication
SQL Server Agent & Job Scheduling
SQL Server Architecture & Editions
SQL Server Profiler & Extended Events
SQL Server Security & Permissions
Stored Procedures & Functions
Subqueries
Temporary Tables & Table Variables
Transactions & ACID
Transparent Data Encryption
Triggers
T-SQL Fundamentals & Syntax
User Defined Functions
Views
Window Functions
XML Data Type & Querying
Query Store
7 questions found
Query Store is a built-in feature that automatically captures a history of queries, their execution plans, and detailed runtime statistics like duration and resource usage over time, giving you a persistent record you can analyze later without needing to have already been actively monitoring the server when a performance problem occurred.
Real-world example
A database administrator enables Query Store on a critical production database, immediately gaining visibility into query performance history that will be invaluable the next time a performance issue needs to be investigated.
Query Optimization & Plans;SQL Server Profiler & Extended Events
You can use the built-in reports available directly in SQL Server Management Studio under the Query Store folder for a database, such as Top Resource Consuming Queries, which visually shows you which queries are using the most CPU, duration, or memory over a selected time period, without needing to write any custom queries yourself.
-- Query Store reports are available in SSMS
-- under Database > Query Store > Top Resource Consuming Queries
Real-world example
A database administrator opens the Top Resource Consuming Queries report in SQL Server Management Studio and immediately identifies a single report query responsible for the majority of CPU usage during peak business hours.
SQL Server Profiler & Extended Events;Query Optimization & Plans
How do you use Query Store to identify a query whose performance has regressed after a recent code deployment?
IntermediateYou use the Query Store's Regressed Queries report, which compares a query's recent performance against an earlier baseline period, highlighting queries that have become noticeably slower, letting you quickly correlate a performance drop with a specific deployment or data change rather than manually searching through logs.
-- The Regressed Queries report compares two time periods
-- automatically highlighting queries that have gotten slower
Real-world example
A team deploys a new feature and later notices overall application slowness, using the Query Store Regressed Queries report to pinpoint the exact query that started performing significantly worse right after the deployment.
Query Optimization & Plans;Deployment
How do you force SQL Server to use a specific, previously known good execution plan for a query using Query Store?
IntermediateYou identify the desired plan id from Query Store's history of captured plans for that query, and use the sp_query_store_force_plan stored procedure to instruct SQL Server to always use that specific plan going forward, which is especially useful for quickly stabilizing performance after a plan regression while you investigate the underlying cause.
EXEC sp_query_store_force_plan
@query_id = 42,
@plan_id = 100;
Real-world example
A database administrator forces a previously fast execution plan for a critical report query after Query Store revealed the optimizer had recently switched to a much slower plan, immediately restoring good performance while the root cause is investigated.
Query Optimization & Plans;Stored Procedures & Functions
How would you configure Query Store's capture and retention settings to balance detailed monitoring with storage overhead on a very busy production database?
AdvancedYou would adjust settings such as the maximum size allocated for Query Store data, the data flush interval controlling how often captured information is written to disk, the statistics collection interval controlling the granularity of captured metrics, and the retention period, tuning these based on how much history you actually need versus the storage and overhead you are willing to accept.
ALTER DATABASE MyDatabase SET QUERY_STORE (
MAX_STORAGE_SIZE_MB = 1000,
INTERVAL_LENGTH_MINUTES = 15,
STALE_QUERY_THRESHOLD_DAYS = 30
);
Real-world example
A busy e-commerce platform carefully tunes its Query Store settings, balancing a reasonable thirty day retention period against a defined storage limit, ensuring they have enough history for troubleshooting without letting Query Store data consume excessive disk space.
SQL Server Architecture & Editions;Backup & Recovery
How can Query Store data be queried directly using its underlying system views for custom analysis beyond the built-in reports?
AdvancedQuery Store exposes several system views such as sys.query_store_query, sys.query_store_plan, and sys.query_store_runtime_stats, which you can join together to write fully custom queries analyzing exactly the metrics and time periods you care about, giving you more flexibility than the built-in reports alone for building specialized dashboards or automated alerts.
SELECT qt.query_sql_text, rs.avg_duration, rs.avg_cpu_time
FROM sys.query_store_query q
JOIN sys.query_store_query_text qt ON q.query_text_id = qt.query_text_id
JOIN sys.query_store_plan p ON q.query_id = p.query_id
JOIN sys.query_store_runtime_stats rs ON p.plan_id = rs.plan_id
ORDER BY rs.avg_duration DESC;
Real-world example
A performance engineering team builds a custom automated alert that queries Query Store's system views directly, notifying the team whenever a query's average duration exceeds a defined threshold, going beyond what the built-in reports alone could provide.
SQL Server Profiler & Extended Events;Query Optimization & Plans
What is the difference between Query Store's READ_WRITE and READ_ONLY operational modes, and when does SQL Server switch between them?
IntermediateIn READ_WRITE mode, Query Store actively captures new query and plan information as queries run, while in READ_ONLY mode it stops capturing new data but still allows you to view previously captured history, which SQL Server automatically switches to if Query Store reaches its configured maximum storage size, requiring you to either increase the size limit or clean up old data to resume active capturing.
-- Check the current operational mode
SELECT actual_state_desc FROM sys.database_query_store_options;
Real-world example
A database administrator notices Query Store has silently stopped capturing new data and discovers it switched to READ_ONLY mode after reaching its storage limit, prompting them to increase the allocated size and clean up old, unnecessary data.
SQL Server Architecture & Editions;Backup & Recovery