O'Reilly logo

Programming Microsoft® SQL Server™ 2008 by Leonard Lobel, Andrew Brust, and Stephen Forte

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TOP Enhancements

In SQL Server 2000 and earlier versions, TOP allows you to limit the number of rows returned as a number or a percentage in SELECT queries. As of SQL Server 2005, you can use TOP in DELETE, UPDATE, and INSERT queries and can also specify the number (or percentage) of rows by using variables or any valid numeric returning expression (such as a subquery). The main reason for allowing TOP with DELETE, UPDATE, and INSERT was to replace the SET ROWCOUNT option, which SQL Server traditionally didn’t optimize very well.

You can specify the TOP limit as a literal number or an expression. If you’re using an expression, you must enclose it in parentheses. The expression should be of the bigint data type when you are not using the PERCENT ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required