I am curious about the logical query processing phase of SQL queries.
我对SQL查询的逻辑查询处理阶段很感兴趣。
For SELECT
queries, the logical query processing phase order is:
对于选择查询,逻辑查询处理阶段顺序为:
- FROM
- 从
- ON
- 在
- OUTER
- 外
- WHERE
- 在哪里
- GROUP BY
- 集团
- CUBE | ROLLUP
- 多维数据集|汇总
- HAVING
- 有
- SELECT
- 选择
- DISTINCT
- 截然不同的
- ORDER BY
- 命令
- TOP
- 前
What is the order for INSERT
, for UPDATE
and for DELETE
?
插入、更新和删除的顺序是什么?
3 个解决方案
#1
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.
如果您想知道实际的查询处理顺序是什么,请查看执行计划。这将一步一步地告诉您SQL Server正在做什么。
https://technet.microsoft.com/en-us/library/ms178071(v=sql.105).aspx
https://technet.microsoft.com/en-us/library/ms178071(v = sql.105). aspx
#2
0
SQL Server: Source
SQL Server:来源
- FROM
- 从
- ON
- 在
- JOIN
- 加入
- WHERE
- 在哪里
- GROUP BY
- 集团
- WITH CUBE or WITH ROLLUP
- 使用立方体或卷取
- HAVING
- 有
- SELECT
- 选择
- DISTINCT
- 截然不同的
- ORDER BY
- 命令
- TOP
- 前
#3
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):
我也有同样的问题,在网上找不到答案。所以我试图从逻辑上推导出答案。下面是一个简单的更新语句(表的别名a):
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).
显然,在确定表之前,无论设置还是在何处都可以执行,因此更新必须是逻辑上的第一步。证明:别名a正在工作(在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)
在应用SET语句之前,需要知道应用它的记录是什么。因此,在第二个逻辑步骤中(省略会改变表中所有记录的地方)
Applying the SET Statement on the WHERE-filtered recordset must be the third step.
对where过滤的记录集应用SET语句必须是第三步。
Summing up, the logical processing order must be:
总结,逻辑处理顺序必须是:
- UPDATE (~equivalent to FROM)
- 更新(~相当于从)
- WHERE
- 在哪里
- 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.
这又是我自己的逻辑推导。我不能肯定。我愿意把任何链接都链接到一个重要的互联网资源上。
#1
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.
如果您想知道实际的查询处理顺序是什么,请查看执行计划。这将一步一步地告诉您SQL Server正在做什么。
https://technet.microsoft.com/en-us/library/ms178071(v=sql.105).aspx
https://technet.microsoft.com/en-us/library/ms178071(v = sql.105). aspx
#2
0
SQL Server: Source
SQL Server:来源
- FROM
- 从
- ON
- 在
- JOIN
- 加入
- WHERE
- 在哪里
- GROUP BY
- 集团
- WITH CUBE or WITH ROLLUP
- 使用立方体或卷取
- HAVING
- 有
- SELECT
- 选择
- DISTINCT
- 截然不同的
- ORDER BY
- 命令
- TOP
- 前
#3
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):
我也有同样的问题,在网上找不到答案。所以我试图从逻辑上推导出答案。下面是一个简单的更新语句(表的别名a):
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).
显然,在确定表之前,无论设置还是在何处都可以执行,因此更新必须是逻辑上的第一步。证明:别名a正在工作(在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)
在应用SET语句之前,需要知道应用它的记录是什么。因此,在第二个逻辑步骤中(省略会改变表中所有记录的地方)
Applying the SET Statement on the WHERE-filtered recordset must be the third step.
对where过滤的记录集应用SET语句必须是第三步。
Summing up, the logical processing order must be:
总结,逻辑处理顺序必须是:
- UPDATE (~equivalent to FROM)
- 更新(~相当于从)
- WHERE
- 在哪里
- 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.
这又是我自己的逻辑推导。我不能肯定。我愿意把任何链接都链接到一个重要的互联网资源上。