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:

Press + to interact
SELECT DISTINCT TOP ColumnName,
MAX(ColumnName)
FROM FirstTable
INNER JOIN SecondTable
ON FirstTable.ColumnName = SecondTable.ColumnName
WHERE Condition
GROUP BY ColumnName
ORDER 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:

Press + to interact

The FROM clause

...