Syntax;
|
[ TOP (expression) [PERCENT] [ WITH TIES ] ]
|
Examples;
|
|
USE AdventureWorks ; GO DECLARE @p AS int SET @p='10' SELECT TOP(@p)* FROM HumanResources.Employee; GO
|
(Books Online – Search for TOP Clause)
But when you use very large table (Ex: more than 1000000) and need to return first 10000 records with using top clause then it will take much time and it can be a performance issue. In that case I am using following method to return first ten thousand records,
USE AdventureWorks ; GO DECLARE @intNum AS int SET @intNum =10000 SET ROWCOUNT @intNum; SELECT * FROM Sales.SalesOrderDetail ORDER BY UnitPrice,SalesOrderID SET ROWCOUNT 0 GO
|
i)Inside the view we can’t use Rowcount option.
ii)Using Rowcount we can’t create sub query’s (Ex. SELECT TMP.SalesOrderID,TMP.UnitPrice FROM (SELECT TOP 10000 * FROM Sales.SalesOrderDetail
ORDER BY UnitPrice,SalesOrderID) TMP)
1 comment:
Good for people to know.
Post a Comment