Home All Groups Group Topic Archive Search About

Get the record count of SQL table w/o retrieving records

Author
24 Nov 2006 8:00 PM
Eve
How can I get a record count of an SQL table without the actual records being
retrieved? This is what I'm using right now and it does take a long time for
big tables:
SELECT COUNT(colName) FROM myTable

Thank you!

Author
24 Nov 2006 11:45 PM
Cowboy (Gregory A. Beamer)
If it is taking a long time, it is most likely due to not having proper
indexes, as basic count functions should be quick. I know of no way faster
than that. If youa re using SQL Server, you might try is profiling and
seeing what SQL Server management tools do when you query a table.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
Show quote
"Eve" <E**@discussions.microsoft.com> wrote in message
news:9E0070A9-4413-4D04-BC56-BFA0D30DDCAA@microsoft.com...
> How can I get a record count of an SQL table without the actual records
> being
> retrieved? This is what I'm using right now and it does take a long time
> for
> big tables:
> SELECT COUNT(colName) FROM myTable
>
> Thank you!
Author
25 Nov 2006 12:43 AM
Jigar Mehta
Hello Eve,

Its good that gregory gave you answer but I dont understand where does .NET
framework come in your question !!

Jigar Mehta
http://jigar-mehta.blogspot.com

E> How can I get a record count of an SQL table without the actual
E> records being
E> retrieved? This is what I'm using right now and it does take a long
E> time for
E> big tables:
E> SELECT COUNT(colName) FROM myTable
E> Thank you!
E>
Author
27 Nov 2006 2:33 PM
KShvats
You can try
SELECT COUNT(1) FROM myTable

Eve wrote:
Show quote
> How can I get a record count of an SQL table without the actual records being
> retrieved? This is what I'm using right now and it does take a long time for
> big tables:
> SELECT COUNT(colName) FROM myTable
>
> Thank you!
Author
27 Nov 2006 2:37 PM
Ciaran O''Donnell
exec sp_MStablespace @name = 'tablename'
Will give the rowcount from the index statistics, these are not garunteed to
be accurate as the statistics may not have been referesh since last
insert/delete. you can call
DBCC UPDATEUSAGE WITH COUNT_ROWS
to update them but this may affect performance as it will take some of SQL
Servers time up.

HTH

Ciaran O'Donnell

Show quote
"Eve" wrote:

> How can I get a record count of an SQL table without the actual records being
> retrieved? This is what I'm using right now and it does take a long time for
> big tables:
> SELECT COUNT(colName) FROM myTable
>
> Thank you!

AddThis Social Bookmark Button