In SQL Server 2008, how can I get a row count for a list of tables?
I have a database where I would like to get the row count for all tables that begin with 'BB'
I've tried multiple variations of this:
CREATE TABLE #RowCounts(NumberOfRows BIGINT, TableName VARCHAR(128))
EXEC sp_MSforeachtable 'INSERT INTO #RowCounts
SELECT COUNT_BIG(*) AS NumberOfRows,
''?'' AS TableName FROM ?'
SELECT TableName, NumberOfRows
FROM #RowCounts
ORDER BY NumberOfRows DESC, TableName
DROP TABLE #RowCounts
Throwing in stuff like ''?'' AS TableName FROM ? WHERE ? LIKE 'BB%'
and ''?'' AS TableName FROM ? WHERE ''?'' LIKE 'BB%'
I'm sure that there has to be a way to do this. If you can get the rowcount for all tables, you should be able to get it for some tables...right?