2007-12-12

[跟電腦比較熟] - SQLServer SQL Script ORDER BY Issue

最近遇到一個SQL Script的問題: 在View裏面寫上ORDER BY是否有效?
得到的結果是:
When ORDER BY is used in the definition of a view, inline function, derived table, or subquery, the clause is used only to determine the rows returned by the TOP clause. The ORDER BY clause does not guarantee ordered results when these constructs are queried, unless ORDER BY is also specified in the query itself.

意思是說:
在view, inline function, derived table, or subquery所使用的ORDER BY只對TOP clause做處理.
例:
Select top (10) percent aaa
From XXXX
Order by aaa

但是對Results而言, 並無Order的功能.

http://msdn2.microsoft.com/en-us/library/ms188385.aspx
http://msdn2.microsoft.com/en-us/library/ms188723.aspx

沒有留言: