Friday, September 5, 2008

Table's row count-you can use alternative way instead of SELECT COUNT(*)

Because SELECT COUNT(*) statement make a full table scan to return the total table's row count, it can take very many time for the large table. There is another way to determine the total row count in a table. You can use sysindexes system table, in this case. There is ROWS column in the sysindexes table. This column contains the total row count for each table in your database. So, you can use the following select statement instead of SELECT COUNT(*):


SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') AND indid < 2

So, you can improve the speed of such queries in several times.

3 comments:

Unknown said...

Hi Renju,
Its very useful one for the speedup the web application as well as windows one.
Thanks!
Prabu

Anonymous said...

How to use select count(*) as total from students;
in asp.net to get counted data ..


Reply:sujayathm@yahoo.co.in

Anonymous said...

Can anyone recommend the top Network Management utility for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: [url=http://www.n-able.com] N-able N-central it automation software
[/url] ? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!