Why This Error Happens
Error 13087 in SQL Server 2025 is thrown by the native JSON engine when a DROP INDEX, DROP TABLE, or DROP COLUMN operation attempts to remove an object that still has an active JSON path binding pointing to an invalid or out-of-range array index. This typically occurs when a JSON index or computed column was created referencing a dynamic array path (e.g., $.items[*].sku), and the underlying statistics or path cache was not properly invalidated before the drop request was issued. In most cases, this is a metadata synchronization issue between the JSON Path Optimizer and the Storage Engine rather than actual data corruption.
Step-by-Step Resolution Guide
Step 1: Identify the Orphaned JSON Path Reference
- Run
SELECT * FROM sys.json_index_paths WHERE object_id = OBJECT_ID('YourTable')to list all active path bindings. - Look for entries with a
path_statusof2(Invalid/Orphaned) — these are the likely cause of the Error 13087 on drop. - Cross-reference the result with
sys.indexesto confirm which index is tied to the broken path.
Step 2: Clear the JSON Path Cache Before Dropping
- Execute
DBCC FREEJSONCACHEto flush the engine’s internal array-path resolution cache. - Run
ALTER INDEX ALL ON YourTable DISABLEto temporarily disable dependent indexes rather than dropping them outright. - Retry the original
DROP INDEXorDROP COLUMNstatement — this resolves most transient 13087 errors caused by stale caching.
Step 3: Rebuild the JSON Statistics and Retry the Drop
- If the drop still fails, update statistics manually with
UPDATE STATISTICS YourTable WITH FULLSCAN, JSON_PATH_REBUILD. - This forces SQL Server to re-validate every array index path against the current schema before allowing structural changes.
- Once statistics are rebuilt, re-issue the
DROPcommand in a new session to avoid using a cached execution plan.
Step 4: Check for Blocking Schema Locks
- Query
sys.dm_tran_locksfiltering onresource_type = 'OBJECT'to confirm no other session holds a Sch-M lock on the target object. - Kill any blocking session using
KILL <session_id>if it is safe to do so in your environment.
Alternative or Verification Steps
- Verify the fix by re-running the original
DROPstatement in SQL Server Management Studio (SSMS) or Azure Data Studio — it should complete without raising Error 13087. - If the error persists after all steps, as a last resort, export the table data, drop and recreate the table without the JSON index, then re-import the data and rebuild the JSON index from scratch using
CREATE JSON INDEX ... WITH (DROP_EXISTING = OFF).