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.