Wednesday, February 24, 2010

SQL Server - Row Count for All Tables

I found this nice simple query here to get a row count for all tables in a SQL Server database:
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC

No comments: