|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Get the record count of SQL table w/o retrieving recordsHow 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. -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA http://gregorybeamer.spaces.live.com ******************************************** Think outside the box! ******************************************** "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! 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> 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! 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! |
|||||||||||||||||||||||