SQL Server - Understanding the order result from tSql queries are returned.

Asked By Erik Little on 07-Jun-14 02:56 PM
I hope I ask this question correctly

I'm attempting to get a better understand of the order results / result sets are returned during the execution of tsql scripts inside stored procedures.

What I'm wanting to understand is when a said stored procedure has many joins and then is followed by the WHERE, ORDER BY, HAVING, nested table queries, ect.. what order are the joins and nested table queries are executed and where the results are stored while the other queries are being executed, what triggers other queries to be executed.

In other words what queries are executed first, where is the results of the queries stored until needed by outer queries, an what triggers the outer queries to execute.

I do not know how to properly has this question so I am not able to Google this question correctly.

I need an explanation of this at a 1st grade level, and then I need an explanation at the graduation level, as in simple explanation first then with this educated foundation I will need to move up to the more in-depth  explanation.

**I not expecting someone to type the answer for this complex question, if someone can provide with with links that already has this documentation that would be a god send.

Thank for the help ahead of time.

Erik

Robbe Morris replied to Erik Little on 08-Jun-14 11:12 AM
The sql server optimizer makes these decisions.  You can see what decisions it makes on a procedure/query basis by putting your code in a management studio query window and selecting Display Execution Plan for the menus under the Query menu option at the top of the screen.

It will tell you what indexes it is using and how it is being used.  Remember to look at the missing index messages to help optimize your index strategy.
Erik Little replied to Robbe Morris on 09-Jun-14 12:37 PM
Thank you.