all groups > sql server programming > october 2005 >
You're in the

sql server programming

group:

Total No. Of Records!


Total No. Of Records! Arpan
10/15/2005 7:03:36 PM
sql server programming:
Apart from using COUNT, are there any other ways to find the total no.
of records existing in a DB table?

Thanks,

Arpan
Re: Total No. Of Records! Dan Guzman
10/15/2005 10:15:35 PM
You can get an approximate count from the sysindexes system table. For
example:

SELECT rows
FROM sysindexes
WHERE id = OBJECT_ID(N'MyTable') AND indid IN(0,1)

The count will be reasonably accurate if you've recently run DBCC
UPDATEUSAGE. However, COUNT is the only accurate method.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

RE: Total No. Of Records! krystian.zieja
10/16/2005 6:32:03 AM
Another option is to use sum aggregate function, i.e.:

select sum(1)
from employees

is equal to

select count(*)
from employees

--
Best Regards
Krystian Zieja / mob


[quoted text, click to view]
Re: Total No. Of Records! Jerry Spivey
10/17/2005 8:12:36 AM
Or if you do decide to use the COUNT function

1. Use COUNT(*) instead of COUNT(column) - may allow the optimizer to use a
smaller NC index
2. Use WITH NOLOCK to help minmize blocking.

HTH

Jerry
[quoted text, click to view]

Re: Total No. Of Records! Raymond D'Anjou
10/17/2005 11:35:44 AM
[quoted text, click to view]

....these 2 Counts will only return the same value if the "column" does not
contains any NULLs.

Here are 2 other methods:
Select * from table
Select @@rowcount

Use a cursor and a counter. (I know, very bad suggestion) :-(

AddThis Social Bookmark Button