Different ways to count rows from a table

Published 02 November 07 08:25 AM | Madhivanan 

The most reliable and suggested method is to use count(*)

1 Select count(*) from table_name

But other than that you can also use one of the followings


2 select sum(1) from table_name
3 select count(1) from table_name
4 select rows from sysindexes where object_name(id)='table_name' and indid<2
5 exec sp_spaceused 'table_name'

PS

To update rows column of sysindexes table, you need to run this before executing methods 4 and 5

DBCC UPDATEUSAGE ('database_name','table_name') WITH COUNT_ROWS.

Filed under: , ,

Comments

# SSQA.net - SqlServer-QA.net said on November 2, 2007 4:02 AM:

The most reliable and suggested method is to use count(*) 1 Select count(*) from table_name But other

# Other SQL Server Blogs around the Web said on November 2, 2007 7:41 AM:

The most reliable and suggested method is to use count(*) 1 Select count(*) from table_name But other

Anonymous comments are disabled

Search

Go

This Blog

«November 2007»
SMTWTFS
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

Syndication