Troubleshooting Guide: SQL Server Error 10745 – “The FORCESCAN hint is not allowed for target tables of INSERT”
Why This Error Happens
This error occurs because the FORCESCAN table hint is only valid for tables being read from (SELECT sources), not for tables that are the target of a data modification operation like INSERT. SQL Server 2025’s query optimizer explicitly blocks this hint on INSERT target tables because scan-forcing logic conflicts with how the storage engine plans row insertion operations. This is almost always caused by a query template, ORM-generated statement, or migrated T-SQL script that incorrectly carries over a FORCESCAN hint meant for a different part of the query (such as a subquery or JOIN source).
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query
- Capture the exact failing statement using SQL Server Profiler, Extended Events, or the Query Store (
sys.query_store_query_text) on the affected database. - Search the query text for the keyword
FORCESCANto locate which table hint clause is causing the conflict. - Check if the query was auto-generated by an ORM (Entity Framework, Hibernate) or a stored procedure template that applies hints globally.
Step 2: Remove or Relocate the Hint
- Open the query in SQL Server Management Studio (SSMS) 21 or Azure Data Studio connected to your Windows Server 2025 instance.
- Delete the
WITH (FORCESCAN)clause specifically from theINSERT INTO TableName WITH (FORCESCAN)portion of the statement. - If a scan hint is genuinely needed, move it to the
SELECTportion of the statement instead, e.g.:
INSERT INTO TargetTable SELECT * FROM SourceTable WITH (FORCESCAN) WHERE ...
Step 3: Update Stored Procedures and Scripts
- Search your deployed stored procedures for recurring instances of this pattern using:
SELECT OBJECT_NAME(object_id), definition FROM sys.sql_modules WHERE definition LIKE '%FORCESCAN%' - Edit and redeploy any procedure found using
ALTER PROCEDURE, ensuring the hint only appears on SELECT-based table references. - If the procedures were generated by a third-party tool or migration script, check the tool’s configuration file (often located in
C:\Program Files\<VendorApp>\config\) for a query hint template setting and disable automatic hint injection on INSERT statements.
Step 4: Clear Cached Execution Plans
- Run
DBCC FREEPROCCACHE(in a test/maintenance window only) or useALTER PROCEDURE ... WITH RECOMPILEon the corrected procedure to ensure no stale plan with the invalid hint remains cached. - Restart the SQL Server service via
services.mscorRestart-Service MSSQLSERVERin PowerShell if the issue persists after plan cache clearing.
Alternative or Verification Steps
- Re-run the corrected
INSERTstatement in SSMS and confirm it executes without Error 10745; also check the SQL Server Error Log (C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) to confirm no recurrence. - As an alternative, replace
FORCESCANwith an index hint directly on the source table (e.g.,WITH (INDEX(IndexName))) if query performance tuning was the original intent behind the hint.