How to: Specify the TOP Clause in Queries
The TOP clause returns only the first n or n percent rows from a query. The TOP clause is useful when you want to inspect a portion of your results to find out if your query does what you expect it to do, without taking the resources necessary to return all of the query results.
Note
This feature is only available if you are connecting to a Microsoft SQL Server database.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.
To specify the TOP clause in queries
Open a query from Solution Explorer or create a new one.
From the View menu, click Properties Window.
In the Properties Window, locate and expand the Top Specification property.
Click the (Top) child property and set it to Yes.
In the Expression child property, type an expression that has a numeric result (for example, "10" or "2*5").
Click the Percent child property and indicate whether or not to treat the Expression property as a percentage of all rows returned (Yes) or as the absolute number of rows returned (No).
If your query uses the ORDER BY clause, click the With Ties child property and choose Yes to display all rows in a group if only part of the group is included or No to truncate them.
As you work through the preceding procedure, notice that the TOP clause, displayed in the SQL pane, changes to reflect the current settings of the properties.
Note
You can also change the values of the child properties of the Top Specification by editing the TOP clause in the SQL pane.