[dba-SQLServer] Order of data in views

jwcolby jwcolby at colbyconsulting.com
Tue May 13 15:34:21 CDT 2008


Well, we are talking about a GroupBy Cnt query here.  The GroupBy field 
is what is ordered on, and is specifically ordered on that field in the 
underlying view.

Unfortunately I cannot execute the view since the view takes about 40 
seconds to complete and MS times out in 30, which no one here has 
managed to show me how to prevent.

Therefore I am forced to create a query and paste the query into that in 
a SELECT * FROM SomeView SQL statement.  Given that the view is ordered, 
you (I) would expect a query directly based on that to be ordered unles 
specifically reordered in some manner.  Not so for whatever reason.

John W. Colby
www.ColbyConsulting.com


Dan Waters wrote:
> I'm not a SQL guy, but wouldn't an unordered view reflect the sort of the
> underlying table?
> 
> Dan
> 
> -----Original Message-----
> From: dba-sqlserver-bounces at databaseadvisors.com
> [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby
> Sent: Tuesday, May 13, 2008 2:18 PM
> To: Dba-Sqlserver
> Subject: [dba-SQLServer] Order of data in views
> 
> In the past I created a set of count views.  For months I have been 
> opening a query window and entering
> 
> SELECT * FROM SomeView.
> 
> The order of the fields was always ordered, now it is not.
> 
> Someone a while back made a comment something like "a view is by its 
> nature unsorted".  Why this would be I haven't a clue since there are 
> order by criteria right in the view, but be that as it may, this has 
> worked in the past and now it is not.
> 
> The issue here is that the client expects to see the data sorted.  So 
> now I have to go do something like:
> 
> SELECT * FROM SomeView Order BY SomeField
> 
> And voila, sorted data.  The issue of course is that it is no longer 
> simple.  I gave to discover the name of the order by field and enter 
> that in my query window.
> 
> Any ideas why it did work and now does not?  How to make it just take 
> the order of the underlying view and pass it through?
> 



More information about the dba-SQLServer mailing list