SQL查询中插入、删除和更新的逻辑查询处理阶段

时间:2022-06-18 21:54:20

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

我对SQL查询的逻辑查询处理阶段很感兴趣。

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

对于选择查询,逻辑查询处理阶段顺序为:

  1. FROM
  2. ON
  3. OUTER
  4. WHERE
  5. 在哪里
  6. GROUP BY
  7. 集团
  8. CUBE | ROLLUP
  9. 多维数据集|汇总
  10. HAVING
  11. SELECT
  12. 选择
  13. DISTINCT
  14. 截然不同的
  15. ORDER BY
  16. 命令
  17. 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:来源

  1. FROM
  2. ON
  3. JOIN
  4. 加入
  5. WHERE
  6. 在哪里
  7. GROUP BY
  8. 集团
  9. WITH CUBE or WITH ROLLUP
  10. 使用立方体或卷取
  11. HAVING
  12. SELECT
  13. 选择
  14. DISTINCT
  15. 截然不同的
  16. ORDER BY
  17. 命令
  18. 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:

总结,逻辑处理顺序必须是:

  1. UPDATE (~equivalent to FROM)
  2. 更新(~相当于从)
  3. WHERE
  4. 在哪里
  5. SET (~equivalent to SELECT)
  6. 集(~相当于选择)

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:来源

  1. FROM
  2. ON
  3. JOIN
  4. 加入
  5. WHERE
  6. 在哪里
  7. GROUP BY
  8. 集团
  9. WITH CUBE or WITH ROLLUP
  10. 使用立方体或卷取
  11. HAVING
  12. SELECT
  13. 选择
  14. DISTINCT
  15. 截然不同的
  16. ORDER BY
  17. 命令
  18. 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:

总结,逻辑处理顺序必须是:

  1. UPDATE (~equivalent to FROM)
  2. 更新(~相当于从)
  3. WHERE
  4. 在哪里
  5. SET (~equivalent to SELECT)
  6. 集(~相当于选择)

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.

这又是我自己的逻辑推导。我不能肯定。我愿意把任何链接都链接到一个重要的互联网资源上。