Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

142


Part II: Building Databases and Working with Data


Summary ...........................................................................................................


The simple SELECT command has a wealth of power and fl exibility.

The key to understanding the SQL query is understanding that the query is declara-
tive — you only phrase a question. The Query Optimizer determines how to execute the
query, so SQL enables some fl exibility in the development style of the query.

Following are a few of the key points from this chapter:

■ (^) Think through the query in the logical fl ow of the query, not the syntax fl ow for
the query.
■ (^) The FROM clause can assemble data from ten different types of data sources. Think
creatively about where you can fi nd data for your query.
■ (^) Never use SELECT *.
■ (^) Aliases are a good thing, and always use the AS.
■ (^) Be intentional about the WHERE clause. Use parentheses. Keep the expressions away
from the source column.
■ (^) Never trust the sort order to the physical order of the data on the disk. If the data
needs to be sorted, then use an ORDER BY.
From this introduction, the next eight chapters incrementally add more advanced features
that augment the power of SELECT: incorporating complex expressions, multiple types of
joins, subqueries, and groupings.
Welcome to the set-based power of SQL.
c06.indd 142c06.indd 142 7/30/2012 4:16:09 PM7/30/2012 4:16:09 PM
http://www.it-ebooks.info

Free download pdf