News

Copyright © 2008-2018 Paula DiTallo

Tag Cloud



SQL Server: Alternative to Count(*) for VLDB


If you have a very large data base (VLDB) a select count(*) can take a long time to resolve. Try this statement as an alternative:

USE YourDatabasename;
SELECT
        s.name AS 'SchemaName'
       ,o.name AS 'TableName'
       ,SUM(p.row_count) AS 'RowCount'
FROM sys.dm_db_partition_stats p
       JOIN sys.objects o ON o.object_id = p.object_id
       JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE p.index_id < 2 AND o.type = 'U'
       AND s.name = 'Schema'
       AND o.name = 'TableName'
GROUP BY s.name,o.name
ORDER BY s.name,o.name;
GO
Friday, December 4, 2015 8:26 AM

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Comment:
Verification: