OPTION
OPTION is a keyword in SQL used to optimize the behavior of a query. It allows for specific instructions to the Query Optimizer about how to implement a query, therefore influencing the choice of the query execution plan. OPTION is written after the execution of main SQL statement. Common uses of OPTION includes limiting the query cost, specifying a join strategy, or controlling the resources used in query execution.
Example
Output
Explanation
The OPTION
clause is used to optimize the performance of your SQL Server query. In this example, the MAXDOP 1
option ensures that the query uses only one processor for its execution, potentially improving performance for a system with multiple processors. The query selects ProductID
and Name
from the Production.Product
table, ordered by ListPrice
in descending order.
Example
Output
Explanation
The OPTION(FULL JOIN)
hint is Oracle’s mechanism for influencing the execution plan of a statement. In the above example, the Oracle SQL engine will perform a FULL JOIN on the tables mentioned in the query. The output shows all employees who are in department 10.