Friday, May 14, 2010

How to get row counts for all tables in a database

I often need to clean out sample data from a database but need to leave static reference data.  I find this script very useful to ensure that I have removed table data that should not remain.

SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + + ']' AS fulltable_name, SCHEMA_NAME(t.schema_id) AS schema_name, AS table_name,
FROM sys.tables AS t INNER JOIN
sys.sysindexes AS i ON t.object_id = AND i.indid < 2 order by rows desc

No comments: