How to fix Error 8720 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 8720 — Multiple TABLE HINT Clauses

Why This Error Happens

This error occurs because a T-SQL query contains more than one TABLE HINT clause (specified via WITH (...)) applied to the same table reference, which SQL Server’s parser does not permit. This is typically introduced by developers manually combining hints (e.g., NOLOCK, INDEX, FORCESEEK) into separate bracketed groups instead of a single comma-separated list within one set of parentheses. It can also surface after migrating legacy scripts or ORM-generated queries to SQL Server 2025, where stricter parser validation now flags syntax that may have been silently tolerated in older engine versions.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Capture the exact failing query text from the application log, SSMS error pane, or Extended Events session.
  • Look for the table name referenced in the error message (replacing %.*ls) to locate the exact object involved.
  • Search the query body for repeated WITH ( blocks attached to the same table alias.

Step 2: Consolidate the TABLE HINT Syntax

  • Locate syntax resembling:
  SELECT * FROM Orders WITH (NOLOCK) WITH (INDEX(IX_Orders_Date))
  • Merge all hints into a single WITH (...) clause separated by commas:
  SELECT * FROM Orders WITH (NOLOCK, INDEX(IX_Orders_Date))
  • Ensure only one WITH (...) block exists per table reference, even if multiple hints are required.

Step 3: Check Stored Procedures, Views, and ORM-Generated Code

  • Use sp_helptext or query sys.sql_modules to scan stored procedures and views for duplicate hint blocks:
  SELECT OBJECT_NAME(object_id), definition
  FROM sys.sql_modules
  WHERE definition LIKE '%WITH (%WITH (%'
  • If the query originates from an ORM (Entity Framework, Hibernate, etc.) or a query-building library, inspect the hint-injection logic, as duplicate hint blocks are often generated programmatically.
  • Patch or update the ORM/query generator layer to emit a single consolidated hint clause.

Step 4: Redeploy and Re-test the Corrected Script

  • Save the corrected procedure/script and redeploy it to the target database using SSMS or your deployment pipeline.
  • Run the corrected query directly in SSMS against Windows Server 2025 / Windows 11 client tools to confirm Error 8720 no longer appears.

Alternative or Verification Steps

  • Re-execute the corrected query in SQL Server Management Studio (SSMS) or Azure Data Studio and confirm it returns results without throwing Error 8720.
  • If the error persists, enable SQL Server’s Query Store or run a trace via Extended Events to capture the exact batch text actually sent to the engine, as application-side query builders sometimes inject hidden duplicate hints not visible in the source code.