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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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!
********************************************
 
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>
 
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
 
Back
Top