Smart Systems for Home

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

SQL Server Error 1017: Hint Cannot Be Specified More Than Once

· 6 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

SQL Server error 1017 means you have written the same query hint more than once in a single query, and the fix is to remove the duplicate so each hint appears only once per query block. For example, if you wrote OPTION (RECOMPILE, RECOMPILE) or repeated MAXDOP in the same OPTION clause, SQL Server rejects the batch with error 1017 before it even compiles. Remove the repeated hint, or consolidate multiple hints into one OPTION clause, and the error goes away.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), Azure Data Studio, or whatever client runs the query.
  • The ability to edit and re-run the query or stored procedure that triggers the error.
  • Permission to alter the procedure or view if the hint lives inside a stored object.
  • A way to view the full error message, including the line number, so you can locate the duplicate hint.

Step-by-Step

  1. Read the full error message. Error 1017 typically reads: "The hint 'RECOMPILE' cannot be specified more than once." The hint name in quotes is your clue. Note it and the line number if your client shows one.
  2. Locate the query that failed. If you are running an ad-hoc batch, find the statement that contains an OPTION clause. If the error comes from a stored procedure, view, or function, use sp_helptext 'YourObjectName' or right-click the object in SSMS and choose Script as > CREATE to see the definition.
  3. Search for the repeated hint. Look for the hint name inside the OPTION (...) clause. Common culprits are RECOMPILE, MAXDOP, OPTIMIZE FOR, USE INDEX, FORCESEEK, and HASH JOIN. The same hint can appear twice in one OPTION list, or once in the query and once inherited from an outer scope.
  4. Remove or merge the duplicate. If you see OPTION (RECOMPILE, RECOMPILE), delete one. If you see OPTION (MAXDOP 4, MAXDOP 8), keep the value you actually want. If the hint appears in two separate OPTION clauses (which is invalid anyway), combine them into a single OPTION clause at the end of the statement.
  5. Check for inherited hints. A query inside a stored procedure can inherit hints from the procedure level. If the procedure has WITH RECOMPILE and the inner query also has OPTION (RECOMPILE), you may get error 1017. Remove the inner hint or the procedure-level setting, whichever is appropriate.
  6. Save and re-run. Execute the corrected query. If it runs without error, you are done. If the error persists, repeat the search for the hint name across the entire batch, including any dynamic SQL strings built with EXEC or sp_executesql.
  7. For stored objects, alter rather than drop. Use ALTER PROCEDURE, ALTER VIEW, or ALTER FUNCTION to apply the fix. This preserves permissions and dependencies. Dropping and recreating works but loses grants and can break referencing objects.
  8. Test with a small batch first. Before deploying the change to production, run the corrected statement in a development or test database to confirm the hint is accepted and the plan is still what you expect.

Common Mistakes

  • Assuming the duplicate is in the same line. The hint may be in a different part of the batch, such as a subquery or a CTE, and the error points to the outer statement.
  • Forgetting about query-level hints in views. A view can contain its own OPTION clause, and when you query the view with another hint, SQL Server may treat them as duplicates.
  • Using two OPTION clauses. A single statement can have only one OPTION clause. If you need multiple hints, put them all inside one set of parentheses, separated by commas.
  • Editing the wrong copy. In a stored procedure with multiple statements, it is easy to fix one occurrence and miss another. Search the entire module text for the hint name.
  • Ignoring dynamic SQL. If the query is built as a string and executed, the duplicate hint may be in the string concatenation, not in the visible T-SQL.
  • Removing a hint that was actually needed. If the hint was there to force a plan, removing it may change performance. Test the plan after the fix.

Tips

  • Use sys.dm_exec_sql_text or the OBJECT_DEFINITION function to retrieve the exact text of the object that failed, so you can search it reliably.
  • Keep hints to a minimum. The more hints you add, the more likely you are to hit conflicts like 1017.
  • When you need multiple hints, list them once each in a single OPTION clause: OPTION (RECOMPILE, MAXDOP 4).
  • If you are using an ORM or query builder, check whether it appends hints automatically. Some tools add OPTION (RECOMPILE) by default, which can collide with a hint you added manually.
  • After fixing, run the query with "Include Actual Execution Plan" enabled to confirm the hint is being applied as intended.

Troubleshooting

If the error persists after removing the obvious duplicate, work through these checks in order:

  1. Search the entire batch for the hint name. Use Ctrl+F in SSMS to find every occurrence of the hint, including inside comments (which are ignored) and inside string literals (which are not).
  2. Check for nested hints. If the query calls a function or view that also has the same hint, SQL Server may consider it a duplicate. Test by running the inner object alone.
  3. Look at the procedure header. A procedure created with WITH RECOMPILE already applies recompile behavior; adding OPTION (RECOMPILE) inside may trigger 1017 in some versions. Remove one of them.
  4. Verify the object definition is current. If you altered the procedure but the error still references the old text, you may be connected to a different database or the change did not commit. Refresh the object in Object Explorer.
  5. Try a minimal reproduction. Create a small query that selects from a single table with the same hint twice. If that fails, you have confirmed the cause. Then add complexity back until the error returns.
  6. Check for client-side hint injection. Some middleware or reporting tools append hints to every query. Review the tool's query settings or connection string options.
  7. If the error occurs in a maintenance plan or agent job, open the job step and inspect the command text. Duplicate hints can be introduced when copying steps between jobs.

Frequently Asked Questions

What does SQL Server error 1017 mean exactly?

It means a query hint was specified more than once in the same query scope. SQL Server allows each hint only once per statement, so repeating it is a syntax-level error.

Can I use the same hint in two different queries in the same batch?

Yes. The restriction is per query block, not per batch. Two separate SELECT statements can each have their own OPTION (RECOMPILE) without error.

Does OPTION (RECOMPILE) conflict with WITH RECOMPILE on a procedure?

In many cases it does not cause error 1017, but it is redundant. If you see 1017, remove the inner hint or the procedure-level setting and test.

Why does the error mention a hint I did not write?

Your client tool, ORM, or a view definition may be adding it. Check the generated SQL and the view text.

Can I fix error 1017 without changing the query?

No. The duplicate hint must be removed or consolidated. There is no server setting that disables this check.

Will removing a duplicate hint change performance?

Possibly. If the hint was forcing a plan, removing the duplicate leaves one instance, which should behave the same. If you remove the only instance, test the plan.