When writing T-SQL, it is important to be familiar with the order in which the SQL Server Database Engine interprets queries, to later create an execution plan. This helps anticipate possible performance issues from poorly written queries. However, it also helps to understand cases of unintended results. The following steps outline the process that the database engine follows to process a T-SQL statement:
- Parse the query for correctness; in other words, validate the syntax.
- Build a structure that represents the logic of the query as expressed by the developer—a query tree, also called a sequence tree.
- Process all the source and target objects stated in the FROM clause (tables, views, TVFs), together with the intended logical operation (JOIN, APPLY) to perform on those objects.
- Apply whatever pre-filters are defined in the WHERE clause...