Further to solution 1 you can join that table with the partitions table to get the row count for each table in a single query
SELECT *
FROM (
SELECT
TableName = t.TABLE_SCHEMA + '.' + t.TABLE_NAME
,[RowCount] = SUM(sp.[ROWS])
FROM INFORMATION_SCHEMA.TABLES t
JOIN sys.partitions sp ON sp.object_id = OBJECT_ID(t.TABLE_SCHEMA + '.' + t.TABLE_NAME)
WHERE TABLE_TYPE = 'BASE TABLE'
GROUP BY t.TABLE_SCHEMA + '.' + t.TABLE_NAME
) A
ORDER BY TableName
This solution was adapted from
this post at sqlserverplanet[
^]
If you decide to loop through the tables using a
CURSOR[
^] then
don't use
SELECT *
.
You only want to know if
any records exist, not view
all of the data so use something like
SELECT TOP 1 FROM [tablename]
or
SELECT COUNT(*) FROM [tablename]