Top Vs Row count

  • Hi all,

    How do 'top' and 'row count' work?

    Which one to use when and why?

    Thanks in advance,

    -kv

  • In SQL2000 ROWCOUNT affects all actions, TOP only affects SELECT

    In SQL2005 TOP can be used with UPDATEs etc.

    Joe Celko has warned me that TOP is not valid ANSI SQL and should be regarded as a MS SQL SERVER only affectation. He is right but I would temper that by saying it has been in the MS SQL Server version of T-SQL since version 7 which must be getting on for a decade now.

    In SQL6.5 and earlier there was no TOP predicate.

  • Hi David,

    I want to retrieve the top 5 rows having a group by clause. I can do this using both rowcount and top. Can u tell me the difference between the exec plans of these two..?? 

  • can you post both queries? these may give you different results (sometimes)

    you can see the difference in the exec plan by pasting in to sql query anlyser and choosing the "show execution plan" option.

    MVDBA

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply