Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1047: Conflicting Locking Hints

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Error 1047 in SQL Server means your query contains two or more table hints that contradict each other, so the optimizer cannot build a valid lock plan. The fix is to remove the conflicting hint, or keep only the one that matches what you actually need. For example, WITH (NOLOCK, HOLDLOCK) is invalid because NOLOCK asks for no shared locks while HOLDLOCK asks for serializable-range locks; likewise WITH (UPDLOCK, NOLOCK) or WITH (TABLOCKX, ROWLOCK) cannot both be honored. You do not need to reinstall anything: open the query, find the hint list, and delete the hint that does not belong.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), Azure Data Studio, or whatever client you use to run the query.
  • The exact text of the failing query, including any table hints in WITH (...) clauses.
  • Permission to edit the query, view, stored procedure, or ORM mapping that contains the hints.
  • Optionally, a non-production database to test the corrected query before deploying.

Step-by-Step

  1. Read the full error message. Error 1047 usually appears as "Conflicting locking hints specified" and may name the object or line. Note the object name and the batch or stored procedure it came from; that tells you where to look.
  2. Locate every table hint in the statement. Hints appear after the table name in a WITH clause, for example FROM dbo.Orders WITH (NOLOCK). Check joined tables too, because a hint on one table can conflict with a query-level hint such as OPTION (MAXDOP ...) only in rare cases, but table-level conflicts are the common cause.
  3. List the hints side by side. Write down each hint and what it does. The usual conflicting pairs are: NOLOCK with HOLDLOCK or SERIALIZABLE; NOLOCK with UPDLOCK; NOLOCK with XLOCK; TABLOCKX with ROWLOCK or PAGLOCK; READPAST with READCOMMITTEDLOCK in some combinations; and any two hints that request different isolation behavior on the same table.
  4. Decide which hint you actually need. If the goal is to avoid blocking readers, keep NOLOCK (or better, use read-committed snapshot isolation at the database level). If the goal is to prevent phantom reads during a transaction, keep HOLDLOCK and drop NOLOCK. If you are taking an exclusive lock for a batch update, keep TABLOCKX and remove row or page granularity hints.
  5. Edit the query and remove the conflicting hint. Delete only the hint that does not match your intent. Do not remove all hints blindly if one is required for correctness, such as UPDLOCK in a queue-processing pattern.
  6. Run the corrected query in a test database first. Execute it and check the execution plan and the results. If the query is inside a stored procedure, use ALTER PROCEDURE to apply the change rather than editing it in production directly.
  7. Check for hidden hints. If the query text looks clean, the hint may come from a view definition, a table-valued function, or an ORM-generated statement. Script the view with sp_helptext or open it in Object Explorer and inspect the WITH clauses inside it.
  8. Deploy the fix and re-test. Run the application path that triggered the error. If the error is gone, monitor for blocking or deadlocks, since removing a hint can change concurrency behavior.

Common Mistakes

  • Removing every hint at once. This can fix the error but change locking behavior and introduce blocking or deadlocks elsewhere. Remove only the conflicting hint.
  • Assuming NOLOCK is harmless. NOLOCK allows dirty reads and can return missing or duplicated rows; it is not a general performance switch.
  • Overlooking hints inside views. A view can carry its own hints, and combining a view hint with a query hint on the same table can trigger 1047.
  • Editing the wrong copy. In replicated or multi-environment setups, the failing statement may live in a different database than the one you are editing.
  • Ignoring ORM-generated SQL. Entity Framework, Dapper, and similar tools can add hints through query interceptors or raw SQL; check the generated statement, not just your C# or Python code.

Tips

  • Prefer isolation-level settings (such as SET TRANSACTION ISOLATION LEVEL or snapshot isolation) over per-table hints when you need consistent reads; it is easier to reason about and avoids hint conflicts.
  • Use sp_helptext or OBJECT_DEFINITION to see the exact stored procedure or view text that SQL Server is compiling.
  • Keep hints documented in code comments so the next person knows why UPDLOCK or HOLDLOCK is there.
  • Test concurrency changes with two sessions: one running the query and one trying to update the same rows, to confirm blocking behavior is acceptable.

Troubleshooting

If the error persists after removing an obvious hint, check whether the query joins a view that itself contains a conflicting hint. Script the view and inspect its WITH clause. If the statement is generated by an application, enable SQL Profiler or Extended Events to capture the exact text sent to the server, since the client may be adding hints you did not write. If the query runs fine in SSMS but fails from the application, compare the session settings and the exact batch text. If you cannot find any hint at all, look for a query-level OPTION clause that conflicts with a table hint, and check whether the object is a synonym pointing to a table with hints in another database. When in doubt, simplify: run the query without any hints in a test database, confirm it works, then add back only the hints you can justify.

Frequently Asked Questions

What causes SQL Server error 1047?

Two or more table hints in the same statement request incompatible locking behavior, such as NOLOCK together with HOLDLOCK or UPDLOCK.

Does removing NOLOCK fix the error?

Often yes, because NOLOCK conflicts with several other hints. But only remove it if you do not rely on its dirty-read behavior; otherwise remove the other hint instead.

Can a view cause error 1047?

Yes. A view can contain its own table hints, and combining them with hints in the outer query can produce the conflict.

Is error 1047 a data corruption issue?

No. It is a query compilation error about hint compatibility, not a storage or corruption problem.

Will the query run if I remove all hints?

It should compile, but locking behavior may change. Test for blocking and deadlocks before deploying to production.