Saturday, February 25, 2012

Records are not listed in order

Hi,
When I used SQL Server Management Studio to open several tables (SQL 2005),
some records are not listed in the order - for example, listed by orderid,
customerid, or so on.
Is there a way that I can have them listed in order?
Many thanks in advance.Hi,
If you do not have a clustered index then data will be displayed based on
the way it gets stored. If you want
any specific order / any batch seeks then go for a clustered index based on
the requirement.
Thanks
Hari
SQL Server MVP
"xfile" <cou-cou@.remove.nospam.com> wrote in message
news:eL4rtqYxGHA.5056@.TK2MSFTNGP06.phx.gbl...
> Hi,
> When I used SQL Server Management Studio to open several tables (SQL
> 2005), some records are not listed in the order - for example, listed by
> orderid, customerid, or so on.
> Is there a way that I can have them listed in order?
> Many thanks in advance.
>|||The ANSI SQL standard states that data will not be stored in any particular
order.
The exception is when there is a 'clustered' index, in which case the data
is ordered by the index.
Always add a [ORDER BY] clause to your queries to retrieve data in a
determined order.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"xfile" <cou-cou@.remove.nospam.com> wrote in message
news:eL4rtqYxGHA.5056@.TK2MSFTNGP06.phx.gbl...
> Hi,
> When I used SQL Server Management Studio to open several tables (SQL
> 2005), some records are not listed in the order - for example, listed by
> orderid, customerid, or so on.
> Is there a way that I can have them listed in order?
> Many thanks in advance.
>|||Hi,
Thanks for both of your explanations.
Just to ensure that I understood correctly, what you meant is that it's
perfectly normal for records not displaying in any particular order if
tables are opened with tool such as Management Studio?
If I wish to have it displayed in any particular order, it has be done by
using queries either by writing one or done with application or tools.
Just one final question about the SQL Server Management Studio and that is,
does it come with any functions similar in Access that can with one click to
have data displaying ascending (A-Z) or descending (Z-A)?
Many thanks.
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:%23OLHKNZxGHA.1272@.TK2MSFTNGP05.phx.gbl...
> The ANSI SQL standard states that data will not be stored in any
> particular order.
> The exception is when there is a 'clustered' index, in which case the data
> is ordered by the index.
> Always add a [ORDER BY] clause to your queries to retrieve data in a
> determined order.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "xfile" <cou-cou@.remove.nospam.com> wrote in message
> news:eL4rtqYxGHA.5056@.TK2MSFTNGP06.phx.gbl...
>|||xfile wrote:
> Hi,
> Thanks for both of your explanations.
> Just to ensure that I understood correctly, what you meant is that it's
> perfectly normal for records not displaying in any particular order if
> tables are opened with tool such as Management Studio?
> If I wish to have it displayed in any particular order, it has be done by
> using queries either by writing one or done with application or tools.
That's right.
Just to expand on what Hari and Arnie said. A clustered index
implements some ordering in an internal index structure (not
necessarily at the level of the data rows or data pages) but it does
not directly control the order in which row will be returned from a
query. For that you need to use an ORDER BY clause.

> Just one final question about the SQL Server Management Studio and that is
,
> does it come with any functions similar in Access that can with one click
to
> have data displaying ascending (A-Z) or descending (Z-A)?
>
No. SSMS is a management tool. It isn't really designed with that kind
of application in mind. Returning every row and then dynamically
sorting them wouldn't be a very sensible feature to have in a client
server environment.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||You can right click on the column and select Pane > Criteria to sort the
result.
KL.
"xfile" <cou-cou@.remove.nospam.com> skrev i meddelandet
news:eL4rtqYxGHA.5056@.TK2MSFTNGP06.phx.gbl...
> Hi,
> When I used SQL Server Management Studio to open several tables (SQL
> 2005), some records are not listed in the order - for example, listed by
> orderid, customerid, or so on.
> Is there a way that I can have them listed in order?
> Many thanks in advance.
>|||You can only guarantee the order of the results by using an
order by clause in the SQL statement.
There is no A-Z or Z-A functionality in SQL Server - that's
just a MS Access thing. All it does is an order by "under
the covers" for you.
When you use an order by clause, you can specify ASC for
ascending or DESC for descending. If you don't specify the
ordering, ASC is the default that will be used.
-Sue
On Tue, 22 Aug 2006 15:50:27 +0800, "xfile"
<cou-cou@.remove.nospam.com> wrote:

>Hi,
>Thanks for both of your explanations.
>Just to ensure that I understood correctly, what you meant is that it's
>perfectly normal for records not displaying in any particular order if
>tables are opened with tool such as Management Studio?
>If I wish to have it displayed in any particular order, it has be done by
>using queries either by writing one or done with application or tools.
>Just one final question about the SQL Server Management Studio and that is,
>does it come with any functions similar in Access that can with one click t
o
>have data displaying ascending (A-Z) or descending (Z-A)?
>Many thanks.
>
>"Arnie Rowland" <arnie@.1568.com> wrote in message
>news:%23OLHKNZxGHA.1272@.TK2MSFTNGP05.phx.gbl...
>|||Hi,
Thanks again for all of your kind explanations.
I did find the pane-criteria, and tried a few times and happy with the
results even I have to add all columns into criteria.
I am totally unfamiliar with database and accustomed to Access simple
graphic interface. We started using SQL 2000 last year (from hosting
company) and all queries are built-in with applications, and we recently
upgraded to a new version of the application and also moved to SQL 2005.
SQL 2005 is fast!!!
The purpose is to open some tables and delete testing data.
Again, many thanks for all of your kind explanations.
"KL" <noname@.nowhere.com> wrote in message
news:OWDzCvexGHA.980@.TK2MSFTNGP04.phx.gbl...
>
> You can right click on the column and select Pane > Criteria to sort the
> result.
> KL.
>
> "xfile" <cou-cou@.remove.nospam.com> skrev i meddelandet
> news:eL4rtqYxGHA.5056@.TK2MSFTNGP06.phx.gbl...
>

No comments:

Post a Comment