Query Execution Process
Learn how the execution sequence of clauses in a query works.
The database engine in SQL Server has a series of steps that it goes through while executing statements. It goes through a series of validations before executing to ensure what we’re running, as far as the query is concerned, is valid. It uses this logical processing to put together the pieces of the query.
Consider the following format for the standard:
SELECT DISTINCT TOP ColumnName,MAX(ColumnName)FROM FirstTableINNER JOIN SecondTableON FirstTable.ColumnName = SecondTable.ColumnNameWHERE ConditionGROUP BY ColumnNameORDER BY ColumnName ASC/DESC
There’s a particular order of operations happening here. Instead of the database engine reading the syntax we write, as we can see from the code, it performs a series of checks to retrieve the data.
Logical processing
The order in which we write a query in SQL differs from the order in which it is logically processed. The sequence of processing by the database is as follows: