Table Size in Microsoft SQL Server
Submitted by TimBruce on Wed, 2010-01-27 13:02
Sometimes I want to find out how many rows are in each user table in a database. The following SQL helps me determine this.
select 'SELECT COUNT(*) AS ' +
'''' +
RTRIM ( name ) +
'''' +
' FROM ' +
RTRIM ( name )
from sysobjects where type = 'U'
order by name
Note: Running this on very large tables or in a database with lots of tables will have a significant negative impact on server performance. This forces a table scan of each table (reading each record).
