sql执行顺序 [英] Sql execution order
问题描述
我对简单的查询感到困惑:
SELECT * FROM table_name WHERE name = 'stack';
我的问题是这部分首先执行:
SELECT * FROM table_name
或
WHERE name = 'stack'
首先从表中选择所有记录,然后使用 WHERE 条件过滤或首先过滤记录然后选择?
有关问题的更多详细信息,请参阅此链接:
谢谢
以下步骤显示了 SELECT 语句的逻辑处理顺序或绑定顺序.此顺序决定了在一个步骤中定义的对象何时可用于后续步骤中的子句.例如,如果查询处理器可以绑定(访问)在 FROM 子句中定义的表或视图,则这些对象及其列可用于所有后续步骤.相反,由于 SELECT 子句是第 8 步,因此该子句中定义的任何列别名或派生列都不能被前面的子句引用.但是,它们可以被后续子句引用,例如 ORDER BY 子句.请注意,语句的实际物理执行由查询处理器决定,顺序可能与此列表不同.
FROM上加入在哪里通过...分组WITH CUBE 或 WITH ROLLUP有选择清楚的订购者最佳
I am confusing with simple query:
SELECT * FROM table_name WHERE name = 'stack';
My question is this which part first execute:
SELECT * FROM table_name
OR
WHERE name = 'stack'
First select all record from table then filter with WHERE condition or first filter records then SELECT?
For more details about question please see this link:
Thanks
The following steps show the logical processing order, or binding order, for a SELECT statement. This order determines when the objects defined in one step are made available to the clauses in subsequent steps. For example, if the query processor can bind to (access) the tables or views defined in the FROM clause, these objects and their columns are made available to all subsequent steps. Conversely, because the SELECT clause is step 8, any column aliases or derived columns defined in that clause cannot be referenced by preceding clauses. However, they can be referenced by subsequent clauses such as the ORDER BY clause. Note that the actual physical execution of the statement is determined by the query processor and the order may vary from this list.
FROM
ON
JOIN
WHERE
GROUP BY
WITH CUBE or WITH ROLLUP
HAVING
SELECT
DISTINCT
ORDER BY
TOP
这篇关于sql执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!