Groups | Blog | Home
all groups > sql server (microsoft) > january 2007 >

sql server (microsoft) : Views



Bill Byrnes
1/21/2007 8:38:46 AM
I am new to SQLServer 2005 but not to relational databases. I am puzzled by
the behavior of views. I can use the view in Visual Studio or open it in
SQLServer Management studio and the virtual table displays correctly except
for sorting (ORDER BY in the SQL statements). Joins and filters all work
correctly when I open the view but not sorting. Sorting will only work if I
open the view with "Modify" and execute it.

I appreciate any help you can give me.

Bill

Russ Rose
1/21/2007 10:02:43 AM

[quoted text, click to view]

Views are not intended to provide sorting for any and all queries against
it. Although SQL 2000 would provide ordering if TOP 100 PERCENT was included
in the view definition, this functionality was not carried forward, I
believe because of performance issues. The ability to include it in a view
definition is for filtering that would require an ordering prior to the
select, such as top five selling items.

Think of a view as a subquery, where ordering would be lost to (overirdden
by) an outer query. It is best to specify ordering in each ouside query,
whether it is on a table, view, or table function.

AddThis Social Bookmark Button