Overview
I'm in the process of reviewing a database for performance analysis. One of the most important tasks to perform is reviewing of statistics. Because this database is currently live, I cannot get the locks to use the sys.dm_db_index_physical_stats built-in function. I have an Oracle background and didn't know how to get the row count quickly. Here's my solution...
References
Solution
I use the following code to get the total number of rows for all tables in the current database:
SELECT sysobjects.[name], max(sysindexes.[rows]) AS TableRows,
CAST(
CASE max(sysindexes.[rows])
WHEN 0 THEN -0
ELSE LOG10(max(sysindexes.[rows]))
END
AS NUMERIC(5,2))
AS L10_TableRows
FROM sysindexes INNER JOIN sysobjects ON sysindexes.[id] = sysobjects.[id]
WHERE sysobjects.xtype = 'U'
GROUP BY sysobjects.[name]
ORDER BY max(rows) DESC
GO
Versions
Metadata