I recently needed to get a quick row count from each table in a large SQL database, and I came across this post that shows two ways to do it. I'm pasting the SQL queries below; read the original post for more information.sp_msforeachtable "Print '?' select count(*) from ?"select convert(varchar(30),object_name(id)) [Table Name], rows from sysindexes
where object_name(id) not like 'sys%' and indid = 1
order by object_name(id)
Friday, July 06, 2007
Retrieving SQL Table Row Counts
Posted by
jwyse
at
1:47 PM
Labels: Development, SQL, Tips
Subscribe to:
Post Comments (Atom)
1 comment:
You probably already know this... :-)
Be sure to run this before doing your count.
DBCC UPDATEUSAGE (DatabaseName)
This will correct any inaccuracies in the sys tables.
You can also run for just one table if needed. See SQL Help for syntax.
Post a Comment