Skip navigation.
Home
Computer Information for the non-computer literate.....

Table Size in Microsoft SQL Server

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).