Fix Error 13681 “A JSON index already exists on column” in SQL Server

If you’re getting SQL Server error 13681 that states “A JSON index already exists on column…” , it’s probably because you’re trying to create a JSON index on a column that already has one. In SQL Server, each JSON column can have no more than one JSON index.

The solution here is to simply stop trying to create a second JSON index. Another option would be to drop the existing one and create the new one.

Read more

Dealing with “Invalid usage of the option ONLINE in the CREATE JSON INDEX statement” in SQL Server

If you’re trying to set the ONLINE option when creating a JSON index in SQL Server, but you’re seeing “Invalid usage of the option ONLINE in the CREATE JSON INDEX statement“, don’t worry – it might not be an error on your part.

It probably depends on things like, are you trying to set ONLINE = ON or ONLINE = OFF? And are you trying to do it around the time I write this article, or sometime in the future?

Let’s take a quick look at what could be happening when you try to use this option.

Read more

JSON Indexes in SQL Server 2025

Before SQL Server 2025, indexing JSON data meant creating a computed column to extract the value you cared about, then indexing that column. It works, and it’s still a solid approach, but it requires you to know upfront which paths you’ll query, maintain separate columns for each one, and keep those columns in sync with any schema changes. SQL Server 2025 introduces JSON indexes as a native alternative. It’s a single index structure that covers the JSON column directly, without the computed column overhead.

JSON indexes are currently in preview and only available in SQL Server 2025 on-premises. They aren’t available yet on Azure SQL Database, Managed Instance, or Fabric. That said, things could be different by the time you read this article.

Read more

What is a Serverless Database?

In the context of cloud databases, a serverless database is one that automatically manages all server resources for you, including scaling up and down based on actual usage, even scaling to zero when not in use. Unlike traditional databases where you provision specific server capacity upfront, serverless databases dynamically allocate resources as needed and charge you only for what you actually consume.

The term “serverless” doesn’t mean there are no servers involved. Servers still exist, but you don’t have to think about them. The cloud provider handles all capacity planning, scaling, and infrastructure management automatically in the background.

Read more

Fix Errors 5133 & 3156 When Restoring a Database in SQL Server

If you’re getting error Msg 5133 and error Msg 3156 in SQL Server, it would seem that you’re trying to restore a database to a different location, but you’re not specifying the different location. This can happen when you restore a database to a different environment that uses a file paths. A common cause of this error is when restoring a backup from a Windows environment to a Linux or Mac environment.

Fortunately, the fix is easy. All you need to do is map the logical file names to paths that actually exist in the new environment.

Read more

Using Multiple Window Calculations with DATEDIFF() 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 provide a great way to analyze temporal patterns in your data.

Window functions can be especially useful when you need to perform multiple different calculations across the same dataset. Instead of writing separate subqueries or self-joins for each calculation, you can combine multiple window expressions in a single query. This approach is cleaner, more maintainable, and often more performant than traditional alternatives.

Read more

How to View Historical Execution Plans for a Query in SQL Server

SQL Server has a feature called Query Store that maintains a history of all execution plans generated for each query over time. Unlike examining the current plan in cache with SHOWPLAN or execution plan tools, Query Store lets you see every plan the optimizer has chosen historically, allowing you to compare performance across plan changes and investigate regressions.

The following examples assume that Query Store is enabled on your database.

Read more

How to Handle “Violation of UNIQUE KEY Constraint” Errors in SQL Server

If you’ve spent any time working with SQL Server, you’ve almost certainly run into the “Violation of UNIQUE KEY constraint” error.

It’s one of those errors that can show up in a few different ways depending on how your data flows into the database. Sometimes it’s a data quality issue. Sometimes it’s a race condition. Sometimes it’s just a gap in the logic that nobody caught until production. Whatever the cause, there are quite a few different ways to handle it. Some reactively, some proactively. This article walks through the main ones.

Read more

Fix Error 13683 “Invalid JSON paths in JSON index” Due to Overlapping Paths in SQL Server

If you’re getting SQL Server error 13683 stating “Invalid JSON paths in JSON index“, it sounds like you could be specifying overlapping paths in your JSON index definition.

A JSON index cannot contain overlapping paths.

To fix this, remove the overlap from the specified paths that make up the index definition.

Read more