11

I am curious about the logical query processing phase of SQL queries.

For SELECT queries, the logical query processing phase order is:

  1. FROM
  2. ON
  3. OUTER
  4. WHERE
  5. GROUP BY
  6. CUBE | ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. ORDER BY
  11. TOP

What is the order for INSERT, for UPDATE and for DELETE?

3 Answers3

1

If you would like to know what the actual query processing order is, take a look at the execution plan. That will tell you step by step exactly what SQL Server is doing.

https://technet.microsoft.com/en-us/library/ms178071(v=sql.105).aspx

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
0

SQL Server: Source

  1. FROM
  2. ON
  3. JOIN
  4. WHERE
  5. GROUP BY
  6. WITH CUBE or WITH ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. ORDER BY
  11. TOP
  • Hi michael.. thank u for the answer. Can you explain what about insert ,update and delete query .. –  Mar 02 '16 at 09:17
  • @Sruthy My understanding is there is no difference. A query plan of a Select/Update/Insert/Delete has no difference apart from the final operator. I'm struggling to find sources to back up my belief though. I welcome anyone who has evidence to the contrary however. – Michael Betterton Mar 03 '16 at 01:12
0

I had the same question and could not find an answer on the internet. So i tried to logically derive the answer. Here is a simple UPDATE statement (with alias a for the table):

UPDATE tbl_employees a
  SET a.Name = 'Anna'
  WHERE a.Id = 122;

Obviously, whether SET nor WHERE can be performed before the table is identified, so UPDATE must be the first logical step. Proof: Alias a is working (in Microsoft Access).

Before applying the SET Statement, one needs to know what records to apply it on. So WHERE must go as the second logical step (omitting WHERE would alter all records in the table)

Applying the SET Statement on the WHERE-filtered recordset must be the third step.

Summing up, the logical processing order must be:

  1. UPDATE (~equivalent to FROM)
  2. WHERE
  3. SET (~equivalent to SELECT)

Any other order seems absurd (can you hypothetically think of any other order?).

Once again, its my own logical derivation. I dont know for sure. I would appriciate any link to a serious internet resource.

JensS
  • 1,151
  • 2
  • 13
  • 20