Re: Create table and default order by clause
- From: "Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 26 Nov 2007 13:53:34 GMT
So, I'm asking if there is a way to define, for a table, a default "order
by" clause to use when no "order by" clause is specified in a "select" query
statement on that table.
No, the only way to guarantee result order is to specify ORDER BY in the SELECT statement that selects from the table.
If not, I think the only alternative is to create a view on that table. Is
it correct?
No, the only way to guarantee result order is to specify ORDER BY in the SELECT statement that selects from the view. Although ORDER BY can be specified in a view along with TOP, it will not guarantee ordering.
Note that it is likely, but not guaranteed, that you will get results ordered in sequence by the table's clustered index in a trivial query with no joins or where clause. However, it's risky to rely on behavior because it may change between SQL Server service packs and releases.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"D." <d@xxxxx> wrote in message news:CQz2j.6583$r62.2270@xxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I have this problem.
My software creates a temporary table (#MyTable).
This table should be used by a report engine and printed each time with
different "order by" clause, depending on some parameters (and the program
that creates the temporary table obviously knows these parameters...)
Now, I don't want to pass these paramete to the report engine, because I
want that the logic of the report will stay only in the program that create
the table (the report engine should onnly do a "SELECT * FROM #MyTable").
So, I'm asking if there is a way to define, for a table, a default "order
by" clause to use when no "order by" clause is specified in a "select" query
statement on that table.
If not, I think the only alternative is to create a view on that table. Is
it correct?
Thanks,
Davide.
.
- References:
- Prev by Date: Create table and default order by clause
- Next by Date: Re: Concat instead of SUM when grouping results
- Previous by thread: Create table and default order by clause
- Next by thread: Re: Create table and default order by clause
- Index(es):
Relevant Pages
|