Query Store captures query execution history, plans, and runtime statistics over time. If you need to stop this data collection (whether to reduce overhead, troubleshoot issues, or prepare for maintenance) you can disable Query Store on a per-database basis.
mssql
Building a Survey Results Dashboard in SQL
Survey data can be messy. You’ve got responses scattered across dozens or hundreds of rows, multiple choice answers, rating scales, and so on. And the challenge of turning all that raw data into something stakeholders can actually understand. A well-designed survey dashboard can transform those individual responses into a grid that shows patterns instantly. For example, which questions are getting strong agreement, where opinions diverge, and what trends emerge across different respondent groups.
Calculating Dynamic Date Offsets with Expressions in SQL Server’s DATEADD() Function
One of DATEADD()‘s less obvious features in SQL Server is its ability to accept expressions as the interval parameter rather than just simple numeric values. You can perform calculations, use arithmetic operations, or reference multiple columns right inside the function call. This gives you a more flexible way to calculate dates when the offset itself needs to be computed based on your data.
So, instead of adding or subtracting a fixed number of days, months, or years, you compute that number on the fly using whatever logic makes sense for your situation. Let’s look at an example that demonstrates this concept.
How to Check Query Wait Statistics in SQL Server’s Query Store (T-SQL)
SQL Server’s Query Store can capture wait statistics that show what queries are waiting on during execution. This includes things like locks, I/O, CPU, memory, and other resources. This can help you understand not just that a query is slow, but why it’s slow. Wait statistics are available in SQL Server 2017 and later.
Using Window Functions with DATEDIFF() to Calculate Moving Averages of Durations in SQL Server
SQL Server’s window functions allow you to perform calculations across sets of rows that are related to the current row, without collapsing those rows into a single result like traditional GROUP BY aggregates would. When combined with the DATEDIFF() function, they can open up many options for analyzing temporal patterns in your data.
Moving averages smooth out short-term fluctuations to reveal longer-term trends in your data. Unlike a simple overall average that treats all historical data equally, a moving average focuses on a sliding window of recent events. This can be quite relevant when analyzing process durations, response times, or any time-based metric where you want to understand current performance trends without being overly influenced by distant historical data.
How to Identify Regressed Queries in SQL Server (T-SQL)
Query regression occurs when a query that previously performed well suddenly becomes slower, often due to a plan change. SQL Server’s Query Store makes it easy to identify these regressions by comparing recent performance against historical baselines.
SQL Server UNPIVOT Explained
Sometimes you need to do the reverse of pivoting – take data that’s spread across multiple columns and convert it back into rows. You might receive data in a wide format from Excel, need to normalize denormalized data for storage, or simply need to reshape data for a different type of analysis. Fortunately, SQL Server has the UNPIVOT operator which is designed for this very scenario.
Whereas PIVOT transforms rows into columns, UNPIVOT transforms column headers back into row values. This creates a narrower, longer dataset from a wide one.
Finding the Most Resource-Intensive Queries in SQL Server
Identifying queries that consume the most resources can help you prioritize performance optimization efforts. In SQL Server you can use Query Store to track CPU time, duration, memory usage, and I/O for every query. This makes it easy to find the biggest resource consumers in your database.
How to Enable Query Store in SQL Server
Query Store is SQL Server’s built-in query performance tracking system that captures execution history, plans, and runtime statistics. From SQL Server 2022 it’s enabled by default for all newly created databases. But in earlier versions, it’s disabled by default, which means you’ll need to explicitly enable it on each database where you want to track query performance.
How to Find Queries with Multiple Execution Plans in SQL Server
When enabled on a database, SQL Server’s Query Store tracks all execution plans that the optimizer generates for each query. When a query has multiple plans, it often indicates parameter sniffing issues, statistics changes, or index modifications that caused the optimizer to choose different execution strategies over time.