The OPTION clause in Microsoft SQL Server (and compatible platforms such as Azure SQL Database and Synapse Analytics) lets you attach query hints directly to an individual SELECT, INSERT, UPDATE, DELETE, or MERGE statement. These hints influence how the query processor chooses execution plans without changing database-wide settings. Common hints include RECOMPILE (do not reuse the cached plan), MAXDOP n (limit degree of parallelism), FAST n (return the first n rows as quickly as possible), OPTIMIZE FOR (explicit parameters), and LOOP JOIN / HASH JOIN (force specific join strategies).OPTION hints are applied after the main statement text and before a terminating semicolon. They affect only the statement they are attached to, leaving other queries and sessions unaffected. If multiple hints conflict, SQL Server returns an error. Some hints, such as RECOMPILE, may increase CPU cost; others, like MAXDOP, can improve concurrency. Always test performance and include OPTION hints only when the default optimizer choices are sub-optimal.The clause is unique to the SQL Server family; other databases either lack it or provide different mechanisms (MySQL optimizer hints, Oracle /*+ */ hints, PostgreSQL GUCs).
query_hint STRING One or more optimizer hints separated by commas. Supported hints include
- RECOMPILE, MAXDOP n, FAST n, HASH JOIN, LOOP JOIN, MERGE JOIN, OPTIMIZE FOR (parameter=value), USE PLAN 'xml_plan', QUERYTRACEON n, etc.QUERY HINT, WITH (INDEX), PLAN GUIDE, OPTIMIZE FOR UNKNOWN, SET HINT, TABLE HINT
SQL Server 2005
Only the single statement that immediately precedes the OPTION clause is affected. Other statements in the batch run with normal optimizer behavior.
Place them inside one pair of parentheses and separate with commas, for example OPTION (HASH JOIN, MAXDOP 4).
SQL Server raises error 8622 and stops execution. Remove or change the conflicting hints.
Yes, when applied judiciously and after testing. Avoid blanket usage; focus on problem queries where the default plan is sub-optimal.