The sorting result of SQL Server is not desired.

Source: Internet
Author: User

In forums, people often ask such questions.:

Why is the result set of the same query sometimes arranged in the desired order, sometimes not, or in the order of SQL2000, to sql2005/2008?

In fact, as long as "order by" is not specified in the statement, sqlserver will not return in order. It is possible that an index has been created for a field in your table.

If you want to sort the result set by the indexed field, it is no problem if you do not specify "order, because the storage order of the table is sorted by the order of the field, you can not specify "order by". However, if you do not create an index for the field you want to sort, you can also create an index in SQL2000, but not in sql2005/2008, so you must explicitly specify the index with "order. If you do not specify the same query,

It is normal that the order of the result set is different from the previous one.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.