Reputation:
I am curious about the logical query processing phase of SQL queries.
For SELECT
queries, the logical query processing phase order is:
What is the order for INSERT
, for UPDATE
and for DELETE
?
Upvotes: 11
Views: 902
Reputation: 1
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:
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.
Upvotes: 0
Reputation: 70327
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
Upvotes: 1
Reputation: 114
SQL Server: Source
Upvotes: 0