Query compilation is the complete process from the submission of a query to its actual execution. There are many steps involved in query compilation—one of which is optimization. All T-SQL statements are compiled, but not all are optimized. Primarily, only the standard SQL Data Manipulation Language (DML) statements—
DELETE—require optimization. The other procedural constructs in T-SQL (
WHILE, local variables, and so on) are compiled as procedural logic but do not require optimization. DML statements are set-oriented requests that the Query Optimizer must translate into procedural code that can be executed efficiently to return the desired results.
SQL Server also optimizes ...