Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Row Count

Author  Topic 

mts
Starting Member

3 Posts

Posted - 2010-06-03 : 18:44:24
How do you get a list of tables and their row counts? I have tried this:

SELECT [TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM sysobjects so,
sysindexes si
WHERE so.xtype = 'U'
AND si.id = OBJECT_ID(so.name)
and so.name = 'TABLE_NAME'
GROUP BY so.name
ORDER BY 2 DESC; -- 14864

select count(*) from TABLE_NAME; -- 14865

For some reason the first query is showing one row less.

Thanks,
-- mts

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-03 : 19:15:30
Was the database upgraded from SQL Server 2000? Has DBCC UPDATEUSAGE been run?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mts
Starting Member

3 Posts

Posted - 2010-06-04 : 10:32:21
I'm not sure what version of SQL Server this database came from. I'm running these queries in 2005.

I ran this:

DBCC UPDATEUSAGE (Database_Name);

I'm getting the same results.
Go to Top of Page
   

- Advertisement -