Top and set rowcount in MSSQL

Source: Internet
Author: User
Tags rowcount
The original articles in online books are as follows:

 

Use top and percent to limit the result set

The top Clause limits the number of rows returned to the result set.

TopN[Percent]

NSpecify the number of returned rows. If percent is not specified,NIs the number of returned rows. If percent is specified,NIs the percentage of rows in the returned result set, as shown below:

Top 120/* return the top 120 rows of the result set. */top 15 percent/* return the top 15% of the result set .*/.

If a SELECT statement contains both the top clause and the order by clause, the returned rows are selected from the sorted result set. The entire result set is created in the specified order and returns the result set in the sorted order.NLine.

Another way to limit the size of a result set is to execute set rowcount before executing a statement.NStatement. The difference between set rowcount and top is:

  • The Set rowcount limit applies to generating rows in the result set after the value of order by is applied. If order by is specified, the SELECT statement selects from a value set that has been sorted according to the specified order by category.NLine.

  • The top clause applies to a single SELECT statement that specifies the clause. Set rowcount remains valid until another set rowcount statement is executed. For example, if set rowcount 0 is executed, this option is disabled.

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.