SQL Server error 1042 means the query you submitted contains two or more optimizer hints that contradict each other, so the optimizer cannot build a plan. The fix is to open the query text, find the hint clauses (usually in an OPTION clause or an INDEX / FORCESEEK / FORCESCAN hint), remove the conflicting pair, and rerun the query. In most cases you only need to delete one hint or replace both with a single hint that expresses the intent you actually want.

The error is a compile-time error, not a runtime one, so it appears before any rows are processed. That is good news: you can reproduce it instantly and you do not need to worry about partial results or data changes. The conflict is almost always between hints that ask for opposite access methods, opposite join types, or opposite parallelism behaviour.

What You'll Need

  • The exact query text that produced the error, including the full OPTION clause. If the query is built dynamically, you also need the code that assembles it.
  • Permission to run the query and, if you plan to change it, permission to alter the procedure, view or application code that contains it.
  • A way to test the change safely, such as a development copy of the database or a transaction you can roll back.
  • SQL Server Management Studio (SSMS) or Azure Data Studio, or whichever client you normally use, so you can see the full error message and the line number it points to.

Step-by-Step

  1. Capture the full error message. Run the query again and read the complete text in the Messages tab. Error 1042 is usually accompanied by a line number and a short description naming the hints involved. Write down the exact message; the wording tells you which hints the optimizer considers incompatible.
  2. Locate every hint in the query. Search the query text for the keyword OPTION and for hint keywords inside table references: NOLOCK, HOLDLOCK, INDEX, FORCESEEK, FORCESCAN, LOOP JOIN, MERGE JOIN, HASH JOIN, MAXDOP, RECOMPILE, OPTIMIZE FOR, and USE PLAN. List them in the order they appear.
  3. Identify the contradictory pair. The common conflicts are: FORCESEEK together with FORCESCAN on the same table; two different join hints such as LOOP JOIN and HASH JOIN for the same pair of tables; INDEX hinting a nonclustered index while another hint forces a scan of the same table; or MAXDOP 1 combined with a hint that requires parallelism. If the query was generated by an ORM or a reporting tool, the hints may be in a template rather than the visible text.
  4. Decide which hint to keep. Ask what the hint was meant to achieve. If it was added to stop a bad plan, keep the hint that addresses that problem and remove the other. If both were added by different people at different times, keep the one that matches current performance needs. When in doubt, remove both and let the optimizer choose; then measure the result.
  5. Edit the query and remove the conflict. Delete the unwanted hint from the OPTION clause or from the table reference. Make sure you remove the comma that separated it if it was not the last item. Save the change in the procedure, view or application code where the query lives, not just in an ad hoc window.
  6. Rerun the query. The 1042 error should disappear immediately because it is raised at compile time. Check the execution plan and the actual runtime to confirm the query still performs acceptably. If performance regressed, add back a single, non-conflicting hint and test again.
  7. Search for the same pattern elsewhere. If the hint came from a template, a code generator or a shared stored procedure, the same conflict probably exists in other queries. Search your codebase for the hint keywords you removed and fix the other occurrences before they reach production.
  8. Document the change. Add a comment above the query explaining why the hint was removed or changed, so the next person does not reintroduce it. If the hint was there for a reason, note the reason and the alternative you chose.

Common Mistakes

The most frequent mistake is removing the wrong hint. If you delete the hint that was preventing a bad plan, the query compiles but runs slowly, and the original problem returns. Always test performance after the edit, not just whether the error is gone.

Another common error is editing only the ad hoc query in SSMS while leaving the stored procedure or application code untouched. The error will come back the next time the application runs. Find the source of the query and fix it there.

People also miss hints that are hidden in dynamic SQL. If the query is assembled with sp_executesql or string concatenation, the conflicting hint may be built at runtime from a variable. Print the final SQL string before execution to see the real text.

Finally, do not replace the removed hint with a different hint that creates a new conflict. Adding FORCESEEK to a query that already has a join hint is fine, but adding FORCESEEK to a table that also has an INDEX hint pointing at a different index can raise the same error again.

Tips

Use the actual execution plan rather than the estimated plan when you are checking performance after removing a hint. The estimated plan can look fine while the actual plan reveals a spill or a bad row estimate.

If you are unsure why a hint was added, check source control history or ask the original author before deleting it. A hint that looks redundant may be protecting against a known optimizer regression on a specific data distribution.

Keep hint usage to a minimum. Every hint you add is a constraint on the optimizer, and constraints multiply the chance of a conflict. Query Store and plan forcing are often better long-term tools than hard-coded hints, and they do not produce error 1042.

When you must keep a hint, put all hints in a single OPTION clause at the end of the query rather than scattering them through the table references. It makes conflicts easier to spot during code review.

Troubleshooting

If the error persists after you remove the obvious conflict, check for hints in a parent query. A view or a common table expression can carry its own hints, and a hint in the outer query can conflict with one inside the view. Expand the view definition and search it for hint keywords.

If you cannot find any hints at all in the query text, the query may be using a plan guide. Check sys.plan_guides for a guide that matches the query, because plan guides inject hints without appearing in the query itself. Drop or alter the guide if it is the source of the conflict.

If the error appears only in one environment, compare the query text between environments. A deployment script or a database upgrade may have added a hint in one place but not the other. Also compare compatibility levels, because hint behaviour can differ between them.

If the query is generated by an application you cannot edit, capture the exact SQL with Extended Events or SQL Server Profiler, then work with the vendor or use a plan guide to override the generated hints. Do not edit system objects or use undocumented trace flags as a workaround.

Frequently Asked Questions

What does SQL Server error 1042 actually mean?

It means the optimizer found two or more hints in the same query that ask for incompatible behaviour, so it cannot produce a plan. The query fails at compile time, before any data is read.

Can error 1042 happen without any hints in my query?

Yes, indirectly. A view, a plan guide or a query template can supply hints that do not appear in the text you are looking at. Check those objects before concluding the query is hint-free.

Does removing a hint always fix the error?

Removing the conflicting hint fixes the compile error, but it may change performance. Test the query after the change and add back a single hint only if you need to stabilise the plan.

Will error 1042 go away after a restart or a statistics update?

No. The conflict is in the query text or in an attached plan guide, so it is deterministic. Restarting SQL Server or updating statistics does not remove hints.

Can I use a plan guide to fix a query I cannot edit?

Yes. A plan guide can supply a replacement plan or a different set of hints for a query you cannot change directly. Create it carefully and test it, because a bad plan guide can cause the same class of error.

Is error 1042 a sign of corruption or a bug?

No. It is a normal validation error raised because the hints are contradictory. It does not indicate database corruption, and it is not usually a product bug.