Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

132


Part II: Building Databases and Working with Data


FIGURE 6-4
Within Management Studio’s Query Designer, you can defi ne the sort order and sort type in the col-
umn pane. The TOP() predicate is set for the Query Designer inside the query’s Properties page.

Although there is not a limit on the number of columns that you can specify in the
ORDER BY clause of the select statement, an internal operation exists that indirectly
enforces a limit. During a sort operation, a worktable see Chapter 44, “Interpreting Query
Execution Plans” is created. This worktable has a maximum row size of 8060 bytes. As a
result, this limits the total size of the columns specifi ed in an ORDER BY clause.

Specifying the ORDER BY Using Column Names
The best way to sort the result set is to completely spell out the ORDER BY columns:

USE AdventureWorks;

SELECT FirstName, LastName

c06.indd 132c06.indd 132 7/30/2012 4:16:05 PM7/30/2012 4:16:05 PM


http://www.it-ebooks.info
Free download pdf