Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Rowcount vs Top

Tags:

tsql

What is the difference between

Set Rowcount X

And

Select Top X *
From Z

in TSQL?

like image 385
C. Ross Avatar asked May 14 '09 14:05

C. Ross


2 Answers

The main difference is that top will only effect the query you are running while set rowcount will persist with the connection and apply to all queries executed within that connection.

like image 180
Andrew Hare Avatar answered Oct 06 '22 15:10

Andrew Hare


Top can do a few more things for you. For one, you can specify a percentage, instead of an integer. You can also handle situations where ties in column values occur.

http://technet.microsoft.com/en-us/library/ms189463.aspx

like image 31
Casey Williams Avatar answered Oct 06 '22 14:10

Casey Williams