The FORCE ORDER is a query hint it executes the order of the tables exactly specified in a statement. When we use this query hint in a statement it will tell SQL server not to change the order of the joins in the query. Basically, the SQL server rearrange your joins to be in the order that it thinks it will be optimal for your query to execute.
Now, Lets see the execution plan without the FORCE ORDER:
The above execution plan demonstrates the optimal order of the joins returned by the SQL server. As you can see the order starts from the sales details and goes by bank details to employee details. Suppose if you don't want the SQL server to change the order of the joins in a query you can use FORCE ORDER to stop the default ordering.
The syntax for FORCE ORDER query hint is,
Now, Lets see the execution plan with the FORCE ORDER:
The statement returned execution plan is,
As you can see the above execution plan starts from employee details and goes by bank details to sales details without changing the order of the joins query.
Now, Lets see the execution plan without the FORCE ORDER:
The above execution plan demonstrates the optimal order of the joins returned by the SQL server. As you can see the order starts from the sales details and goes by bank details to employee details. Suppose if you don't want the SQL server to change the order of the joins in a query you can use FORCE ORDER to stop the default ordering.
The syntax for FORCE ORDER query hint is,
Now, Lets see the execution plan with the FORCE ORDER:
As you can see the above execution plan starts from employee details and goes by bank details to sales details without changing the order of the joins query.
Comments