IT tutorials
 
Technology
 

SQL Server 2012 : Understanding Query Flow (part 2) - Logical Flow of the Query Statement, Physical Flow of the Query Statement

4/19/2014 1:45:06 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Logical Flow of the Query Statement

The best way to think through a SQL DML statement is to walk through the query's logical flow (see Figure 2). Because SQL is a declarative language, the logical flow may or may not be the actual physical flow that SQL Server's query processor uses to execute the query. Nor is the logical flow the same as the query syntax. Regardless, think through a query in the following order.

Figure 2 A simplified view of the logical flow of the query showing how data moves through the major clauses of the SQL select command.

6.2

Following is a more detailed explanation of the logical flow of the query. Every step except step 4 is optional:

1. [From]: The query begins by assembling the initial set of data, as specified in the FROM portion of the SELECT statement.
2. [Where]: The filter process is actually the WHERE clause, selecting only those rows that meet the criteria.
3. [Aggregations]: SQL can optionally perform aggregations on the data set, such as finding the average, grouping the data by values in a column, and filtering the groups.
4. Column Expressions: The SELECT list is processed, and any expressions are calculated .
5. [Order By]: The resulting rows are sorted according to the ORDER BY clause, which can be ascending or descending. The default sort order is ascending.
6. [Over]: Windowing and ranking functions can provide a separately ordered view of the results with additional aggregate functions.
7. [Distinct]: Any duplicate rows are eliminated from the result set.
8. [Top]: After the rows are selected, the calculations are performed, and the data is sorted into the wanted order, SQL can restrict the output to the top few rows.
9. [Insert, Update, Delete]: The final logical step of the query is to apply the data modification action to the results of the query.
10. [Output]: The inserted and deleted virtual tables (normally only used with a trigger) can be selected and returned to the client, inserted into a table, or serve as a data source to an outer query.
11. [Union]: The results of multiple queries can be stacked or combined using a union command .

As more complexity has been added to the SQL SELECT command over the years, how to think through the logical flow has also become more complex. In various sources, you can find minor differences in how SQL professionals view the logical flow. That's OK — it's just a way to think through a query.

As you begin to think in terms of the SQL SELECT statement, rather than in terms of the graphical user interface, understanding the flow of SELECT and how to read the query execution plan can help you think through and develop difficult queries.

Physical Flow of the Query Statement

SQL Server can take the SELECT statement and develop an optimized query execution plan, which may not be in the execution order you would guess (see Figure 3). The indexes available to the SQL Server Query Optimizer also affect the query execution plan.

Figure 3 The physical execution plan is different from the syntactical order, or logical understanding, of the query.

6.3
 
Others
 
- SQL Server 2012 : Understanding Query Flow (part 1) - Syntactical Flow of the Query Statement, A Graphical View of the Query Statement
- Windows Server 2012 : Deploying and configuring virtual machines (part 5) - Configuring virtual machine management
- Windows Server 2012 : Deploying and configuring virtual machines (part 4) - Adding and configuring virtual network adapters
- Windows Server 2012 : Deploying and configuring virtual machines (part 3) - Configuring virtual machines - Adding virtual disks
- Windows Server 2012 : Deploying and configuring virtual machines (part 2) - Creating virtual machines
- Windows Server 2012 : Deploying and configuring virtual machines (part 1) - Planning virtual machine deployment
- Sharepoint 2013 : Manage Tags and Notes
- Sharepoint 2013 : Follow Colleagues to See What They Are Posting
- Sharepoint 2013 : Use Microblogging to Let Others Know What You Are Doing or Thinking
- Sharepoint 2013 : Get Started with Social Features
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us