Monday, March 23, 2009

Get list of all tables in SQL and its approximate row count

Here's the SQL to do this.
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

Kewl, huh!?
Reference: here

No comments: