When you’ve forced an execution plan in SQL Server’s query store and later want to allow the optimizer to choose plans freely again, you’ll need to unforce the plan. You might want to do this because you’ve fixed the underlying issue or the forced plan is no longer optimal. Whatever the reason, the solution is straightforward and easy.
DBMS
Database Management Systems
Generating Staggered Dates with SQL Server Window Functions
SQL Server’s window functions open up some creative possibilities when you need to work with dates. One interesting pattern involves pairing DATEADD() with ROW_NUMBER() to automatically generate sequential dates based on your query results.
This technique gives you a flexible way to calculate dates dynamically without hardcoding values or maintaining separate date tables. This can be useful for doing things like building a scheduling system, creating test data with realistic timestamps, or just spacing events across a timeline.
Understanding Locks in SQL Server
If you’ve ever wondered why your database queries sometimes seem to wait around doing nothing, or why two users can’t update the same record at the exact same moment, you’re dealing with locks. In SQL Server, locks are the fundamental mechanism that keeps your data consistent and prevents the chaos that would ensue if everyone could modify everything simultaneously.
How to Clear Query Store Data in SQL Server
SQL Server’s Query Store accumulates query execution history, plans, and runtime statistics over time. Eventually you may need to remove this data to free up space, start fresh after troubleshooting, or clear out information that’s no longer relevant. Fortunately, you can clear Query Store data without disabling the feature entirely.
How to Force a Query Execution Plan in SQL Server
When the optimizer consistently chooses a poor execution plan for a query, you can force SQL Server to use a specific better-performing plan from Query Store. This can provide immediate relief while you investigate and fix the root cause of the poor plan choice.
List of Query Store Configuration Options in SQL Server
SQL Server’s Query Store provides a handy way to track query performance over time, making it easier to troubleshoot issues and optimize workloads. To get the most out of it, it helps to understand the various configuration options that control how it collects, stores, and manages data.
How to Disable Query Store in SQL Server
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.
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.