Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Order of Execution of SQL Queries

$
0
0
I am curious about the order of execution of SQL Queries.  I did a bit of research on this.  I found this:

 

http://stackoverflow.com/questions/4596467/order-of-execution-of-the-query

 

In that link, someone stated the following:

 

'SQL has no order of execution. Is a declarative language. The optimizer is free to choose any order it feels appropriate to produce the best execution time. Given any SQL query, is basically impossible to anybody to pretend it knows the execution order. If you add detailed information about the schema involved (exact tables and indexes definition) and the estimated cardinalities (size of data and selectivity of keys) then one can take a guess at the probable execution order.'

 

Really?  There is NO ORDER???

 

In the link below, Dave states the following:

 

http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/

 

What actually sets SQL Server apart from other programming languages is the way SQL Server processes its code. Generally, most programming languages process statement from top to bottom. By contrast, SQL Server processes them in a unique order which is known as Logical Query Processing Phase. These phases generate a series of virtual tables with each virtual table feeding into the next phase (virtual tables not viewable). These phases and their orders are given as follows:

 

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

 

Again, I was just curious about this concept. I’ve been using SQL for a long time.  I’ve thought about this before, but not seriously. Today, I’m thinking about it from an academic perspective.

 

Thanks for the insight, everyone!!

 

 


Ryan Shuell


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>