Get list of tables in MS-SQL with row count - part 2

In a previous article I showed how to get the row count for a limited set of tables.  Here is code I found at http://stackoverflow.com/questions/2221555/how-to-fetch-the-row-count-for-all-tables-in-a-sql-server-database that works very nicely:

 

SELECT o.name,
ddps.row_count
FROM sys.indexes AS i
INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID
INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID
AND i.index_id = ddps.index_id
WHERE i.index_id < 2 AND o.is_ms_shipped = 0 ORDER BY o.NAME

 

 This is extremely fast and will get you the rowcount for the entire database in less than a second - as I understand it pretty much no matter how many rows you have in it!

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk