1DECLARE @TableRowCounts TABLE ([TableName] VARCHAR(128), [RowCount] INT) ;
2INSERT INTO @TableRowCounts ([TableName], [RowCount])
3EXEC sp_MSforeachtable 'SELECT ''?'' [TableName], COUNT(*) [RowCount] FROM ?' ;
4SELECT [TableName], [RowCount]
5FROM @TableRowCounts
6ORDER BY [TableName]
7GO
8